@@ -18,31 +18,47 @@ export default function createProvider(React) {
18
18
const storeShape = createStoreShape ( PropTypes ) ;
19
19
const requireFunctionChild = isUsingOwnerContext ( React ) ;
20
20
21
- let didWarn = false ;
22
- function warnAboutFunction ( ) {
23
- if ( didWarn || requireFunctionChild ) {
21
+ let didWarnAboutChild = false ;
22
+ function warnAboutFunctionChild ( ) {
23
+ if ( didWarnAboutChild || requireFunctionChild ) {
24
24
return ;
25
25
}
26
26
27
- didWarn = true ;
27
+ didWarnAboutChild = true ;
28
28
console . error ( // eslint-disable-line no-console
29
29
'With React 0.14 and later versions, you no longer need to ' +
30
30
'wrap <Provider> child into a function.'
31
31
) ;
32
32
}
33
- function warnAboutElement ( ) {
34
- if ( didWarn || ! requireFunctionChild ) {
33
+ function warnAboutElementChild ( ) {
34
+ if ( didWarnAboutChild || ! requireFunctionChild ) {
35
35
return ;
36
36
}
37
37
38
- didWarn = true ;
38
+ didWarnAboutChild = true ;
39
39
console . error ( // eslint-disable-line no-console
40
40
'With React 0.13, you need to ' +
41
41
'wrap <Provider> child into a function. ' +
42
42
'This restriction will be removed with React 0.14.'
43
43
) ;
44
44
}
45
45
46
+ let didWarnAboutReceivingStore = false ;
47
+ function warnAboutReceivingStore ( ) {
48
+ if ( didWarnAboutReceivingStore ) {
49
+ return ;
50
+ }
51
+
52
+ didWarnAboutReceivingStore = true ;
53
+ console . error ( // eslint-disable-line no-console
54
+ '<Provider> does not support changing `store` on the fly. ' +
55
+ 'It is most likely that you see this error because you updated to ' +
56
+ 'Redux 2.x and React Redux 2.x which no longer hot reload reducers ' +
57
+ 'automatically. See https://github.com/rackt/react-redux/releases/' +
58
+ 'tag/v2.0.0 for the migration instructions.'
59
+ ) ;
60
+ }
61
+
46
62
return class Provider extends Component {
47
63
static childContextTypes = {
48
64
store : storeShape . isRequired
@@ -57,32 +73,31 @@ export default function createProvider(React) {
57
73
} ;
58
74
59
75
getChildContext ( ) {
60
- return { store : this . state . store } ;
76
+ return { store : this . store } ;
61
77
}
62
78
63
79
constructor ( props , context ) {
64
80
super ( props , context ) ;
65
- this . state = { store : props . store } ;
81
+ this . store = props . store ;
66
82
}
67
83
68
84
componentWillReceiveProps ( nextProps ) {
69
- const { store } = this . state ;
85
+ const { store } = this ;
70
86
const { store : nextStore } = nextProps ;
71
87
72
88
if ( store !== nextStore ) {
73
- const nextReducer = nextStore . getReducer ( ) ;
74
- store . replaceReducer ( nextReducer ) ;
89
+ warnAboutReceivingStore ( ) ;
75
90
}
76
91
}
77
92
78
93
render ( ) {
79
94
let { children } = this . props ;
80
95
81
96
if ( typeof children === 'function' ) {
82
- warnAboutFunction ( ) ;
97
+ warnAboutFunctionChild ( ) ;
83
98
children = children ( ) ;
84
99
} else {
85
- warnAboutElement ( ) ;
100
+ warnAboutElementChild ( ) ;
86
101
}
87
102
88
103
return Children . only ( children ) ;
0 commit comments