UNPKG

recoil

Version:

Recoil - A state management library for React

55 lines (45 loc) 2.33 kB
/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @emails oncall+recoil * @flow strict-local * @format */ 'use strict'; import type { Loadable } from '../adt/Recoil_Loadable'; import type { DependencyMap } from './Recoil_Graph'; import type { DefaultValue } from './Recoil_Node'; import type { AtomValues, NodeKey, Store, TreeState } from './Recoil_State'; const { mapByDeletingFromMap, mapBySettingInMap, setByAddingToSet } = require('../util/Recoil_CopyOnWrite'); const { getNode, getNodeMaybe } = require('./Recoil_Node'); // flowlint-next-line unclear-type:off const emptySet: $ReadOnlySet<any> = Object.freeze(new Set()); declare class ReadOnlyRecoilValueError extends Error {} // Get the current value loadable of a node and update the state. // Update dependencies and subscriptions for selectors. // Update saved value validation for atoms. declare function getNodeLoadable<T>(store: Store, state: TreeState, key: NodeKey): [DependencyMap, Loadable<T>]; // Peek at the current value loadable for a node without any evaluation or state change declare function peekNodeLoadable<T>(store: Store, state: TreeState, key: NodeKey): ?Loadable<T>; // Write value directly to state bypassing the Node interface as the node // definitions may not have been loaded yet when processing the initial snapshot. declare function setUnvalidatedAtomValue_DEPRECATED<T>(state: TreeState, key: NodeKey, newValue: T): TreeState; // Return the discovered dependencies and values to be written by setting // a node value. (Multiple values may be written due to selectors getting to // set upstreams; deps may be discovered because of reads in updater functions.) declare function setNodeValue<T>(store: Store, state: TreeState, key: NodeKey, newValue: T | DefaultValue): [DependencyMap, AtomValues]; declare function cleanUpNode(store: Store, key: NodeKey): any; // Find all of the recursively dependent nodes declare function getDownstreamNodes(store: Store, state: TreeState, keys: $ReadOnlySet<NodeKey>): $ReadOnlySet<NodeKey>; module.exports = { getNodeLoadable, peekNodeLoadable, setNodeValue, cleanUpNode, setUnvalidatedAtomValue_DEPRECATED, getDownstreamNodes };