-
Notifications
You must be signed in to change notification settings - Fork 1
/
storeact.js
45 lines (39 loc) · 1.07 KB
/
storeact.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
import {Component} from 'react';
export default class Storeact extends Component {
constructor(props) {
super(props);
this.state = {};
this.stores = [];
// wrap the optional mount / unmount functions with stores
this.componentWillMount = doMount.bind(this)(this.componentWillMount);
this.componentWillUnmount = doUnmount.bind(this)(this.componentWillUnmount);
}
bindStores(stores) {
this.stores = stores;
}
}
function doMount(callAfter) {
return () => {
if (this.UpdateStore) {
this.UpdateStore = this.UpdateStore.bind(this);
this.stores.map((item) => {
item.connect(this.UpdateStore);
});
}
if (callAfter) {
callAfter.bind(this)();
}
}
}
function doUnmount(callAfter) {
return () => {
if (this.UpdateStore) {
this.stores.map((item) => {
item.disconnect(this.UpdateStore);
});
}
if (callAfter) {
callAfter.bind(this)();
}
}
}