Skip to content
This repository was archived by the owner on Jul 30, 2018. It is now read-only.

Commit 57fddfc

Browse files
authored
Convert to use TS2.2 Class Mixins over dojo/compose (#326)
* convert to TS2.2 * add support for render decorators * changes required to support TS mixins * missing shims * adding interfaces to generate declaration files * missed state * fix up * drop support for IE10 * clean up and doc * remove example code and custom Gruntfile config * add decorator for base classes * add Properties as generic and remove WidgtOptions * use correct properties * properties not options in the constructor * fix unit tests for projector
1 parent c1e8803 commit 57fddfc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2661
-3083
lines changed

Gruntfile.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
module.exports = function (grunt) {
2-
require('grunt-dojo2').initConfig(grunt, {
3-
/* any custom configuration goes here */
4-
});
2+
require('grunt-dojo2').initConfig(grunt, {});
53
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"remap-istanbul": "^0.6.4",
6161
"sinon": "^1.17.6",
6262
"tslint": "^3.11.0",
63-
"typescript": "~2.1.4"
63+
"typescript": "rc"
6464
},
6565
"dependencies": {
6666
"@dojo/compose": "2.0.0-beta.21",

src/FactoryRegistry.ts

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,66 @@
1-
import { isComposeFactory } from '@dojo/compose/compose';
21
import Promise from '@dojo/shim/Promise';
32
import Map from '@dojo/shim/Map';
4-
import {
5-
WidgetBaseFactory,
6-
FactoryRegistryInterface,
7-
FactoryRegistryItem,
8-
WidgetFactoryFunction
9-
} from './interfaces';
3+
import { WidgetBase, WidgetConstructor } from './WidgetBase';
104

5+
/**
6+
* A function the returns a Promise<WidgetConstructor>
7+
*/
8+
export type WidgetFactoryFunction = () => Promise<WidgetConstructor>
9+
10+
/**
11+
* Factory Registry Item - Either WidgetConsructor, Promise for a WidgetConstructor or WidgetFactoryFunction
12+
*/
13+
export type FactoryRegistryItem = WidgetConstructor | Promise<WidgetConstructor> | WidgetFactoryFunction
14+
15+
/**
16+
* Factory Registry Interface
17+
*/
18+
export interface FactoryRegistryInterface {
19+
20+
/**
21+
* define a FactoryRegistryItem for a specified label
22+
*
23+
* @param factoryLabel The label of the factory to register
24+
* @param registryItem The registry item to define
25+
*/
26+
define(factoryLabel: string, registryItem: FactoryRegistryItem): void;
27+
28+
/**
29+
* Return a Factory or promise for a factory for the given label, null if an entry doesn't exist
30+
*
31+
* @param factoryLabel The label of the factory to return
32+
* @returns The Factory or Promise for the label, `null` if no entry exists
33+
*/
34+
get(factoryLabel: string): WidgetConstructor | Promise<WidgetConstructor> | null;
35+
36+
/**
37+
* Returns a boolean if an entry for the label exists
38+
*
39+
* @param factoryLabel The label to search for
40+
* @returns boolean indicating if a factory exists
41+
*/
42+
has(factoryLabel: string): boolean;
43+
}
44+
45+
/**
46+
* Checks is the item is a subclass of WidgetBase (or a WidgetBase)
47+
*
48+
* @param item the item to check
49+
* @returns true/false indicating is the item is a WidgetConstructor
50+
*/
51+
export function isWidgetBaseConstructor(item: any): item is WidgetConstructor {
52+
return WidgetBase.isPrototypeOf(item) || item === WidgetBase;
53+
}
54+
55+
/**
56+
* The FactoryRegistry implementation
57+
*/
1158
export default class FactoryRegistry implements FactoryRegistryInterface {
12-
protected registry: Map<string, FactoryRegistryItem>;
59+
60+
/**
61+
* internal map of labels and FactoryRegistryItem
62+
*/
63+
private registry: Map<string, FactoryRegistryItem>;
1364

1465
constructor() {
1566
this.registry = new Map<string, FactoryRegistryItem>();
@@ -26,18 +77,19 @@ export default class FactoryRegistry implements FactoryRegistryInterface {
2677
this.registry.set(factoryLabel, registryItem);
2778
}
2879

29-
get(factoryLabel: string): WidgetBaseFactory | Promise<WidgetBaseFactory> | null {
80+
get(factoryLabel: string): WidgetConstructor | Promise<WidgetConstructor> | null {
3081
if (!this.has(factoryLabel)) {
3182
return null;
3283
}
3384

3485
const item = this.registry.get(factoryLabel);
3586

36-
if (isComposeFactory(item) || item instanceof Promise) {
87+
if (item instanceof Promise || isWidgetBaseConstructor(item)) {
3788
return item;
3889
}
3990

4091
const promise = (<WidgetFactoryFunction> item)();
92+
4193
this.registry.set(factoryLabel, promise);
4294

4395
return promise.then((factory) => {

0 commit comments

Comments
 (0)