UNPKG

redux-fluorine

Version:

A Redux enhancer to manage groups of actions as observables (agendas)

49 lines (37 loc) 1.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = reapplyActionsWithout; function reapplyActionsWithout(reducer, base, subtract) { var diverged = false; var anchor = base.lastValidState || base; var lastValid = anchor; while (anchor.next) { // Iterate to next state anchor = anchor.next; var _anchor = anchor; var action = _anchor.action; if (subtract.indexOf(action) > -1) { // Prevent recomputation of any states until it's actually // necessary diverged = true; // Link last valid state for any agenda that might have stored // this state as its anchor anchor.lastValidState = lastValid; } else { if (diverged) { // Recompute state anchor.state = reducer(lastValid.state, action); } // Link the last valid state to this equally valid one and // replace the lastValid reference with this state lastValid.next = anchor; lastValid = anchor; } } // Make sure that the lastValid state is not pointing anywhere and // return it lastValid.next = null; return lastValid; }