forked from Workiva/react-dart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdart_helpers.js
72 lines (63 loc) · 2.67 KB
/
dart_helpers.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
/**
* react-dart JS interop helpers (used by react_client.dart and react_client/js_interop_helpers.dart)
*/
function _getProperty(obj, key) { return obj[key]; }
function _setProperty(obj, key, value) { return obj[key] = value; }
function _createReactDartComponentClassConfig(dartInteropStatics, componentStatics, jsConfig) {
var config = {
getInitialState: function() {
this.dartComponent = dartInteropStatics.initComponent(this, this.props.internal, this.context, componentStatics);
return {};
},
componentWillMount: function() {
dartInteropStatics.handleComponentWillMount(this.dartComponent);
},
componentDidMount: function() {
dartInteropStatics.handleComponentDidMount(this.dartComponent);
},
componentWillReceiveProps: function(nextProps, nextContext) {
dartInteropStatics.handleComponentWillReceiveProps(this.dartComponent, nextProps.internal, nextContext);
},
shouldComponentUpdate: function(nextProps, nextState, nextContext) {
return dartInteropStatics.handleShouldComponentUpdate(this.dartComponent, nextContext);
},
componentWillUpdate: function(nextProps, nextState, nextContext) {
dartInteropStatics.handleComponentWillUpdate(this.dartComponent, nextContext);
},
componentDidUpdate: function(prevProps, prevState) {
dartInteropStatics.handleComponentDidUpdate(this.dartComponent, prevProps.internal);
},
componentWillUnmount: function() {
dartInteropStatics.handleComponentWillUnmount(this.dartComponent);
},
render: function() {
return dartInteropStatics.handleRender(this.dartComponent);
}
};
// React limits the accessible context entries
// to the keys specified in childContextTypes/contextTypes.
var childContextKeys = jsConfig && jsConfig.childContextKeys;
var contextKeys = jsConfig && jsConfig.contextKeys;
if (childContextKeys && childContextKeys.length !== 0) {
config.childContextTypes = {};
for (var i = 0; i < childContextKeys.length; i++) {
config.childContextTypes[childContextKeys[i]] = React.PropTypes.object;
}
// Only declare this when `childContextKeys` is non-empty to avoid unnecessarily
// creating interop context objects for components that won't use it.
config.getChildContext = function() {
return dartInteropStatics.handleGetChildContext(this.dartComponent);
};
}
if (contextKeys && contextKeys.length !== 0) {
config.contextTypes = {};
for (var i = 0; i < contextKeys.length; i++) {
config.contextTypes[contextKeys[i]] = React.PropTypes.object;
}
}
return config;
}
function _markChildValidated(child) {
var store = child._store;
if (store) store.validated = true;
}