-
Notifications
You must be signed in to change notification settings - Fork 76
/
create.js
82 lines (64 loc) · 2.17 KB
/
create.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var constants = require('./constants');
var StateMixin = require('./stateMixin');
var createContainer = require('./createContainer');
var createStoreClass = require('./store/createStoreClass');
var createQueriesClass = require('./queries/createQueriesClass');
var createStateSourceClass = require('./stateSource/createStateSourceClass');
var createActionCreatorsClass = require('./actionCreators/createActionCreatorsClass');
var DEFAULT_CLASS_NAME = 'Class';
module.exports = {
register: register,
createStore: createStore,
createQueries: createQueries,
createContext: createContext,
createContainer: createContainer,
createConstants: createConstants,
createStateMixin: createStateMixin,
createStateSource: createStateSource,
createActionCreators: createActionCreators,
};
function register(clazz, id) {
var className = getClassName(clazz);
if (!clazz.id) {
clazz.id = id || className;
}
if (!clazz.displayName) {
clazz.displayName = clazz.id;
}
return this.registry.register(clazz);
}
function createContext() {
return this.registry.createContext();
}
function getClassName(clazz) {
var funcNameRegex = /function (.{1,})\(/;
var results = (funcNameRegex).exec(clazz.toString());
var className = (results && results.length > 1) ? results[1] : '';
return className === DEFAULT_CLASS_NAME ? null : className;
}
function createConstants(obj) {
return constants(obj);
}
function createStateMixin(options) {
return new StateMixin(options);
}
function createStore(properties) {
var StoreClass = createStoreClass(properties);
var defaultInstance = this.register(StoreClass);
return defaultInstance;
}
function createActionCreators(properties) {
var ActionCreatorsClass = createActionCreatorsClass(properties);
var defaultInstance = this.register(ActionCreatorsClass);
return defaultInstance;
}
function createQueries(properties) {
var QueriesClass = createQueriesClass(properties);
var defaultInstance = this.register(QueriesClass);
return defaultInstance;
}
function createStateSource(properties) {
var StateSourceClass = createStateSourceClass(properties);
var defaultInstance = this.register(StateSourceClass);
return defaultInstance;
}