|
@@ -1,71 +1,73 @@
|
1
|
|
-import * as _ from 'lodash';
|
2
|
1
|
import * as React from 'react';
|
|
2
|
+import * as _ from 'lodash';
|
|
3
|
+
|
|
4
|
+interface State {
|
|
5
|
+ componentId: string,
|
|
6
|
+ allProps: {}
|
|
7
|
+}
|
3
|
8
|
|
4
|
9
|
export class ComponentWrapper {
|
5
|
|
- static wrap(componentName: string, OriginalComponent: any, store: any) {
|
6
|
|
- return class extends React.Component<any, any> {
|
7
|
|
- constructor(props) {
|
8
|
|
- super(props);
|
9
|
|
- this._saveComponentRef = this._saveComponentRef.bind(this);
|
10
|
|
- this._assertComponentId(props);
|
11
|
|
- this.state = {
|
12
|
|
- componentId: props.componentId,
|
13
|
|
- allProps: _.merge({}, props, store.getPropsForComponentId(props.componentId))
|
14
|
|
- };
|
|
10
|
+ static wrap(componentName: string, OriginalComponentClass: React.ComponentClass | React.StatelessComponent, store: any): React.ComponentClass {
|
|
11
|
+ class WrappedComponent extends React.Component<any, State> {
|
|
12
|
+ render() {
|
|
13
|
+ return <div />;
|
15
|
14
|
}
|
|
15
|
+ };
|
16
|
16
|
|
17
|
|
- _assertComponentId(props) {
|
18
|
|
- if (!props.componentId) {
|
19
|
|
- throw new Error(`Component ${componentName} does not have a componentId!`);
|
20
|
|
- }
|
21
|
|
- }
|
|
17
|
+ return WrappedComponent;
|
|
18
|
+ }
|
|
19
|
+}
|
22
|
20
|
|
23
|
|
- _saveComponentRef(r) {
|
24
|
|
- this.originalComponentRef = r;
|
25
|
|
- }
|
|
21
|
+// this._saveComponentRef = this._saveComponentRef.bind(this);
|
|
22
|
+// this._assertComponentId(props);
|
|
23
|
+// this.state = {
|
|
24
|
+// componentId: props.componentId,
|
|
25
|
+// allProps: _.merge({}, props, store.getPropsForComponentId(props.componentId))
|
|
26
|
+// };
|
26
|
27
|
|
27
|
|
- componentWillMount() {
|
28
|
|
- store.setRefForComponentId(this.state.componentId, this);
|
29
|
|
- }
|
|
28
|
+// _assertComponentId(props) {
|
|
29
|
+// if (!props.componentId) {
|
|
30
|
+// throw new Error(`Component ${componentName} does not have a componentId!`);
|
|
31
|
+// }
|
|
32
|
+// }
|
30
|
33
|
|
31
|
|
- componentWillUnmount() {
|
32
|
|
- store.cleanId(this.state.componentId);
|
33
|
|
- }
|
|
34
|
+// _saveComponentRef(r) {
|
|
35
|
+// this.originalComponentRef = r;
|
|
36
|
+// }
|
34
|
37
|
|
35
|
|
- didAppear() {
|
36
|
|
- if (this.originalComponentRef.didAppear) {
|
37
|
|
- this.originalComponentRef.didAppear();
|
38
|
|
- }
|
39
|
|
- }
|
|
38
|
+// componentWillMount() {
|
|
39
|
+// store.setRefForComponentId(this.state.componentId, this);
|
|
40
|
+// }
|
40
|
41
|
|
41
|
|
- didDisappear() {
|
42
|
|
- if (this.originalComponentRef.didDisappear) {
|
43
|
|
- this.originalComponentRef.didDisappear();
|
44
|
|
- }
|
45
|
|
- }
|
|
42
|
+// componentWillUnmount() {
|
|
43
|
+// store.cleanId(this.state.componentId);
|
|
44
|
+// }
|
46
|
45
|
|
47
|
|
- onNavigationButtonPressed(buttonId) {
|
48
|
|
- if (this.originalComponentRef.onNavigationButtonPressed) {
|
49
|
|
- this.originalComponentRef.onNavigationButtonPressed(buttonId);
|
50
|
|
- }
|
51
|
|
- }
|
|
46
|
+// didAppear() {
|
|
47
|
+// if (this.originalComponentRef.didAppear) {
|
|
48
|
+// this.originalComponentRef.didAppear();
|
|
49
|
+// }
|
|
50
|
+// }
|
52
|
51
|
|
53
|
|
- componentWillReceiveProps(nextProps) {
|
54
|
|
- this.setState({
|
55
|
|
- allProps: _.merge({}, nextProps, store.getPropsForComponentId(this.state.componentId))
|
56
|
|
- });
|
57
|
|
- }
|
|
52
|
+// didDisappear() {
|
|
53
|
+// if (this.originalComponentRef.didDisappear) {
|
|
54
|
+// this.originalComponentRef.didDisappear();
|
|
55
|
+// }
|
|
56
|
+// }
|
58
|
57
|
|
59
|
|
- render() {
|
60
|
|
- return (
|
61
|
|
- <OriginalComponent
|
62
|
|
- ref= { this._saveComponentRef }
|
63
|
|
- {...this.state.allProps }
|
64
|
|
- componentId = { this.state.componentId }
|
65
|
|
- key = { this.state.componentId }
|
66
|
|
- />
|
67
|
|
- );
|
68
|
|
- }
|
69
|
|
- };
|
70
|
|
- }
|
71
|
|
-}
|
|
58
|
+// onNavigationButtonPressed(buttonId) {
|
|
59
|
+// if (this.originalComponentRef.onNavigationButtonPressed) {
|
|
60
|
+// this.originalComponentRef.onNavigationButtonPressed(buttonId);
|
|
61
|
+// }
|
|
62
|
+// }
|
|
63
|
+
|
|
64
|
+// componentWillReceiveProps(nextProps) {
|
|
65
|
+// this.setState({
|
|
66
|
+// allProps: _.merge({}, nextProps, store.getPropsForComponentId(this.state.componentId))
|
|
67
|
+// });
|
|
68
|
+// }
|
|
69
|
+
|
|
70
|
+// ref= { this._saveComponentRef }
|
|
71
|
+// {...this.state.allProps }
|
|
72
|
+// componentId = { this.state.componentId }
|
|
73
|
+// key = { this.state.componentId }
|