Closed ShinyChang closed 4 years ago
function useSnapshotWithStateChange( transaction: (<T>(RecoilState<T>, (T) => T) => void) => void, ): UpdatedSnapshot { const storeRef = useStoreRef(); let snapshot = useTreeStateClone(); const update = <T>({key}: RecoilState<T>, updater: T => T) => { [snapshot] = setNodeValue( storeRef.current, snapshot, key, peekNodeLoadable(storeRef.current, snapshot, key).map(updater), ); }; transaction(update); const atomValues: Map<NodeKey, mixed> = mapMap( snapshot.atomValues, v => v.contents, ); // Only report atoms, not selectors const updatedAtoms = intersectSets( snapshot.dirtyAtoms, new Set(atomValues.keys()), ); return {atomValues, updatedAtoms}; }
Expected:
Actual: