@@ -53,16 +53,30 @@ var AltContainer = React.createClass({
53
53
throw new ReferenceError ( 'Cannot define both store and stores' )
54
54
}
55
55
56
- return this . getStateFromStores ( ) || { }
56
+ return this . getStateFromStores ( this . props ) || { }
57
+ } ,
58
+
59
+ componentWillReceiveProps : function ( nextProps ) {
60
+ this . destroySubscriptions ( )
61
+ this . setState ( this . getStateFromStores ( nextProps ) )
62
+ this . registerStores ( nextProps )
57
63
} ,
58
64
59
65
componentDidMount : function ( ) {
66
+ this . registerStores ( this . props )
67
+ } ,
68
+
69
+ componentWillUnmount : function ( ) {
70
+ this . destroySubscriptions ( )
71
+ } ,
72
+
73
+ registerStores : function ( props ) {
60
74
Subscribe . create ( this )
61
75
62
- if ( this . props . store ) {
63
- this . addSubscription ( this . props . store )
64
- } else if ( this . props . stores ) {
65
- var stores = this . props . stores
76
+ if ( props . store ) {
77
+ this . addSubscription ( props . store )
78
+ } else if ( props . stores ) {
79
+ var stores = props . stores
66
80
67
81
if ( Array . isArray ( stores ) ) {
68
82
stores . forEach ( function ( store ) {
@@ -76,26 +90,26 @@ var AltContainer = React.createClass({
76
90
}
77
91
} ,
78
92
79
- componentWillUnmount : function ( ) {
93
+ destroySubscriptions : function ( ) {
80
94
Subscribe . destroy ( this )
81
95
} ,
82
96
83
- getStateFromStores : function ( ) {
84
- if ( this . props . store ) {
85
- return getState ( this . props . store , this . props )
86
- } else if ( this . props . stores ) {
87
- var stores = this . props . stores
97
+ getStateFromStores : function ( props ) {
98
+ if ( props . store ) {
99
+ return getState ( props . store , props )
100
+ } else if ( props . stores ) {
101
+ var stores = props . stores
88
102
89
103
// If you pass in an array of stores the state is merged together.
90
104
if ( Array . isArray ( stores ) ) {
91
105
return stores . reduce ( function ( obj , store ) {
92
- return assign ( obj , getState ( store , this . props ) )
106
+ return assign ( obj , getState ( store , props ) )
93
107
} . bind ( this ) , { } )
94
108
95
109
// if it is an object then the state is added to the key specified
96
110
} else {
97
111
return Object . keys ( stores ) . reduce ( function ( obj , key ) {
98
- obj [ key ] = getState ( stores [ key ] , this . props )
112
+ obj [ key ] = getState ( stores [ key ] , props )
99
113
return obj
100
114
} . bind ( this ) , { } )
101
115
}
@@ -104,14 +118,14 @@ var AltContainer = React.createClass({
104
118
}
105
119
} ,
106
120
107
- addSubscription : function ( store ) {
121
+ addSubscription : function ( store ) {
108
122
if ( typeof store === 'object' ) {
109
123
Subscribe . add ( this , store , this . altSetState )
110
124
}
111
125
} ,
112
126
113
127
altSetState : function ( ) {
114
- this . setState ( this . getStateFromStores ( ) )
128
+ this . setState ( this . getStateFromStores ( this . props ) )
115
129
} ,
116
130
117
131
getProps : function ( ) {
0 commit comments