/** * 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. * * Logic for reading, writing, and subscribing to atoms within the context of * a particular React render tree. EVERYTHING IN THIS MODULE SHOULD BE PURE * FUNCTIONS BETWEEN IMMUTABLE TreeState VALUES. It is permissible to call * `getAtomDef` because atom definitions are constant. * * @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 = 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(store: Store, state: TreeState, key: NodeKey): [DependencyMap, Loadable]; // Peek at the current value loadable for a node without any evaluation or state change declare function peekNodeLoadable(store: Store, state: TreeState, key: NodeKey): ?Loadable; // 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(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(store: Store, state: TreeState, key: NodeKey, newValue: T | DefaultValue): [DependencyMap, AtomValues]; // Find all of the recursively dependent nodes declare function getDownstreamNodes(store: Store, state: TreeState, keys: $ReadOnlySet): $ReadOnlySet; module.exports = { getNodeLoadable, peekNodeLoadable, setNodeValue, setUnvalidatedAtomValue, getDownstreamNodes };