mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
State and context are on the public instance
This commit is contained in:
1 parent
f352fe2625
commit
3137553f6d
1 file changed
+16
-6
@@ -560,8 +560,12 @@ export function attach(
|
||||
}
|
||||
}
|
||||
}
|
||||
context = internalInstance.context || null;
|
||||
state = internalInstance.state || null;
|
||||
|
||||
const publicInstance = internalInstance._instance;
|
||||
if (publicInstance != null) {
|
||||
context = publicInstance.context || null;
|
||||
state = publicInstance.state || null;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -696,16 +700,22 @@ export function attach(
|
||||
function setInState(id: number, path: Array<string | number>, value: any) {
|
||||
const internalInstance = idToInternalInstanceMap.get(id);
|
||||
if (internalInstance != null) {
|
||||
setIn(internalInstance.state, path, value);
|
||||
internalInstance.forceUpdate();
|
||||
const publicInstance = internalInstance._instance;
|
||||
if (publicInstance != null) {
|
||||
setIn(publicInstance.state, path, value);
|
||||
forceUpdate(publicInstance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setInContext(id: number, path: Array<string | number>, value: any) {
|
||||
const internalInstance = idToInternalInstanceMap.get(id);
|
||||
if (internalInstance != null) {
|
||||
setIn(internalInstance.context, path, value);
|
||||
forceUpdate(internalInstance);
|
||||
const publicInstance = internalInstance._instance;
|
||||
if (publicInstance != null) {
|
||||
setIn(publicInstance.context, path, value);
|
||||
forceUpdate(publicInstance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user