recoil
Version:
Recoil - A state management library for React
37 lines (30 loc) • 1.02 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.
*
* @flow strict-local
* @format
* @oncall recoil
*/
;
import type {RecoilValueReadOnly} from '../core/Recoil_RecoilValue';
import type {Parameter} from './Recoil_selectorFamily';
const selectorFamily = require('./Recoil_selectorFamily');
// flowlint-next-line unclear-type:off
const constantSelector = selectorFamily<any, any>({
key: '__constant',
get: constant => () => constant,
cachePolicyForParams_UNSTABLE: {
equality: 'reference',
},
});
// Function that returns a selector which always produces the
// same constant value. It may be called multiple times with the
// same value, based on reference equality, and will provide the
// same selector.
function constSelector<T: Parameter>(constant: T): RecoilValueReadOnly<T> {
return constantSelector(constant);
}
module.exports = constSelector;