-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,11 +57,19 @@ export const useReduxState = () => { | |
lastState.current = state; | ||
}); | ||
// trapped | ||
const proxyMap = useRef(new WeakMap()); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
dai-shi
Author
Owner
|
||
const trappedMap = useRef(new WeakMap()); | ||
const lastTrapped = useRef(null); | ||
const trapped = proxyState(state); | ||
let trapped; | ||
useEffect(() => { | ||
lastTrapped.current = trapped; | ||
}); | ||
if (trappedMap.current.has(state)) { | ||
trapped = trappedMap.current.get(state); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} else { | ||
trapped = proxyState(state, null, proxyMap.current); | ||
trappedMap.current.set(state, trapped); | ||
} | ||
// subscription | ||
useEffect(() => { | ||
const callback = () => { | ||
|
That would be cool to have proxy mapping as a top-level variable, so different
useReducers
could benefit from it.(requires guaranteed synchronous code to remove any races, hooks, probably, guarantee it.