UNPKG

recoil-sync-next

Version:

recoil-sync stores for Next.js

20 lines (19 loc) 821 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.initializableAtomFamily = void 0; const recoil_1 = require("recoil"); function initializableAtomFamily(options) { const baseAtom = (0, recoil_1.atomFamily)({ ...options, default: undefined, }); const evaluationSelector = (0, recoil_1.selectorFamily)({ key: `${options.key}::withInitialValue`, get: ({ param, initialValue }) => ({ get }) => { var _a; return (_a = get(baseAtom(param))) !== null && _a !== void 0 ? _a : initialValue; }, set: ({ param }) => ({ set }, newValue) => set(baseAtom(param), newValue), }); return (param, initialValue) => { return evaluationSelector({ param, initialValue }); }; } exports.initializableAtomFamily = initializableAtomFamily;