recoil
Version:
Recoil - A state management library for React
38 lines (31 loc) • 929 B
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';
const selectorFamily = require('./Recoil_selectorFamily');
const err = require('recoil-shared/util/Recoil_err');
// flowlint-next-line unclear-type:off
const throwingSelector = selectorFamily<any, any>({
key: '__error',
get: message => () => {
throw err(message);
},
// TODO Why?
cachePolicyForParams_UNSTABLE: {
equality: 'reference',
},
});
// Function that returns a selector which always throws an error
// with the provided message.
function errorSelector<T>(message: string): RecoilValueReadOnly<T> {
return throwingSelector(message);
}
module.exports = errorSelector;