recoil
Version:
Recoil - A state management library for React
128 lines (105 loc) • 3.75 kB
Flow
/**
* 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
*/
;
import type { RecoilValue } from '../core/Recoil_RecoilValue';
import type { MutableSnapshot } from '../core/Recoil_Snapshot';
import type { Store, StoreRef, StoreState } from '../core/Recoil_State';
const React = require('React');
const {
useContext,
useEffect,
useMemo,
useRef,
useState
} = require('React'); // @fb-only: const RecoilusagelogEvent = require('RecoilusagelogEvent');
// @fb-only: const RecoilUsageLogFalcoEvent = require('RecoilUsageLogFalcoEvent');
// @fb-only: const URI = require('URI');
const Queue = require('../adt/Recoil_Queue');
const {
cleanUpNode,
getDownstreamNodes,
setNodeValue,
setUnvalidatedAtomValue_DEPRECATED
} = require('../core/Recoil_FunctionalCore');
const {
graph,
saveDependencyMapToStore
} = require('../core/Recoil_Graph');
const {
cloneGraph
} = require('../core/Recoil_Graph');
const {
applyAtomValueWrites
} = require('../core/Recoil_RecoilValueInterface');
const {
freshSnapshot
} = require('../core/Recoil_Snapshot');
const {
getNextTreeStateVersion,
makeEmptyStoreState
} = require('../core/Recoil_State');
const {
mapByDeletingMultipleFromMap
} = require('../util/Recoil_CopyOnWrite');
const nullthrows = require('../util/Recoil_nullthrows'); // @fb-only: const recoverableViolation = require('../util/Recoil_recoverableViolation');
const Tracing = require('../util/Recoil_Tracing');
const unionSets = require('../util/Recoil_unionSets'); // @fb-only: const gkx = require('gkx');
type Props = {
initializeState_DEPRECATED?: ({
set: <T>(RecoilValue<T>, T) => void,
setUnvalidatedAtomValues: (Map<string, mixed>) => void,
}) => void,
initializeState?: (MutableSnapshot) => void,
store_INTERNAL?: Store,
children: React.Node,
};
declare function notInAContext(): any;
const defaultStore: Store = Object.freeze({
getState: notInAContext,
replaceState: notInAContext,
getGraph: notInAContext,
subscribeToTransactions: notInAContext,
addTransactionMetadata: notInAContext
});
let stateReplacerIsBeingExecuted: boolean = false;
declare function startNextTreeIfNeeded(storeState: StoreState): void;
const AppContext = React.createContext<StoreRef>({
current: defaultStore
});
declare var useStoreRef: () => StoreRef;
const MutableSourceContext = React.createContext<mixed>(null); // TODO T2710559282599660
declare var useRecoilMutableSource: () => mixed;
declare function sendEndOfBatchNotifications(store: Store): any;
/*
* The purpose of the Batcher is to observe when React batches end so that
* Recoil state changes can be batched. Whenever Recoil state changes, we call
* setState on the batcher. Then we wait for that change to be committed, which
* signifies the end of the batch. That's when we respond to the Recoil change.
*/
declare function Batcher(props: {
setNotifyBatcherOfChange: (() => void) => void
}): any;
if (__DEV__) {
if (typeof window !== 'undefined' && !window.$recoilDebugStates) {
window.$recoilDebugStates = [];
}
} // When removing this deprecated function, remove stateBySettingRecoilValue
// which will no longer be needed.
declare function initialStoreState_DEPRECATED(store: any, initializeState: any): StoreState;
declare function initialStoreState(initializeState: any): StoreState;
let nextID = 0;
declare function RecoilRoot(arg0: Props): ReactElement;
module.exports = {
useStoreRef,
useRecoilMutableSource,
RecoilRoot,
sendEndOfBatchNotifications_FOR_TESTING: sendEndOfBatchNotifications
};