UNPKG

map-transform-cjs

Version:
82 lines (81 loc) 2.38 kB
// src/utils/xor.ts function xor(a = false, b = false) { return a ? !b : b; } // src/utils/stateHelpers.ts var getLastContext = (state) => state.context[state.context.length - 1]; var removeLastContext = (state) => ({ ...state, context: state.context.slice(0, -1) }); var pushContext = (state, value) => ({ ...state, context: [...state.context, value] }); var popContext = (state) => ({ ...state, context: state.context.slice(0, -1), value: state.context[state.context.length - 1] }); var getRootFromState = (state) => state.context.length === 0 ? state.value : state.context[0]; var getTargetFromState = (state) => state.target; function setTargetOnState(state, target) { return { ...state, target }; } var setStateValue = ({ untouched, ...state }, value, shouldPushContext = false) => shouldPushContext ? { ...pushContext(state, state.value), value } : { ...state, value }; var getStateValue = (state) => state.value; var setValueFromState = (state, { value }, shouldPushContext = false) => setStateValue(state, value, shouldPushContext); var isNonvalue = (value, nonvalues = [void 0]) => nonvalues.includes(value); var isNonvalueState = (state, nonvalues = [void 0]) => isNonvalue(state.value, nonvalues); var markAsUntouched = (state) => ({ ...state, untouched: true }); var clearUntouched = ({ untouched, ...state }) => state; var isUntouched = ({ untouched }) => !!untouched; var populateState = (data, { rev = false, noDefaults = false, target = void 0 }) => ({ context: [], value: data, target, rev, noDefaults }); var goForward = (state) => state.rev || state.flip ? { ...state, rev: false, flip: false } : state; var flipState = (state, flip = true) => ({ ...state, flip: xor(state.flip, flip) }); var stopIteration = (state) => ({ ...state, iterate: false }); var noopNext = async (state) => state; var revFromState = (state, flip = false) => flip ? xor(state.rev, !state.flip) : xor(state.rev, state.flip); export { clearUntouched, flipState, getLastContext, getRootFromState, getStateValue, getTargetFromState, goForward, isNonvalue, isNonvalueState, isUntouched, markAsUntouched, noopNext, popContext, populateState, pushContext, removeLastContext, revFromState, setStateValue, setTargetOnState, setValueFromState, stopIteration }; //# sourceMappingURL=stateHelpers.js.map