UNPKG

@medamajs/compose

Version:

Composable state management extension for medama with support for hierarchical state layers, dynamic composition, and parallel state synchronization

29 lines 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.traverseThroughPupils = void 0; const traverseThroughPupils = (pupilRecords, processLayer, final) => { let i = 0; let selectorToSeal = false; let acc; const stepLogic = () => { const nextPupilWithKey = pupilRecords[i++]; const [, { readState }] = nextPupilWithKey; const nextStep = createStep(...nextPupilWithKey); return readState(nextStep); }; const createStep = (key, { subscribeToState }) => { const stepEmitted = (state) => { if (selectorToSeal) return undefined; acc = processLayer(key, state, subscribeToState, stepEmitted, acc); if (i < pupilRecords.length) return stepLogic(); selectorToSeal = true; return final(acc); }; return stepEmitted; }; return stepLogic(); }; exports.traverseThroughPupils = traverseThroughPupils; //# sourceMappingURL=traverseThroughPupils.js.map