How to use the updeep.updateIn function in updeep

To help you get started, we’ve selected a few updeep examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kresusapp / kresus / client / store / banks.js View on Github external
function removeAccess(state, accessId) {
    assert(
        typeof accessId === 'number',
        'The second parameter of removeAccess should be a number id'
    );

    // First remove all the accounts attached to the access.
    let newState = state;
    for (let accountId of accountIdsByAccessId(state, accessId)) {
        newState = removeAccount(newState, accountId);
    }

    // Then remove access (should have been done by removeAccount).
    newState = updateAccessesMap(newState, u.omit(accessId));
    newState = u.updateIn('accessIds', u.reject(id => id === accessId), newState);

    // Sort again accesses in case the default account has been deleted.
    return sortAccesses(newState);
}
github Venryx / DebateMap / Source / Store / main / mapViews / $mapView / rootNodeViews.ts View on Github external
export function RootNodeViewsReducer(state = new RootNodeViews(), action: Action, mapID: number) {
	// for performance reasons, we do portions of some actions "at the root", instead of using the descendant reducers
	// ==========

	// if we're selecting a new node, at-root deselect the old selected node
	if (action.Is(ACTMapNodeSelect)) {
		let nodes = GetTreeNodesInObjTree(state, true);

		let selectedNode = nodes.FirstOrX(a=>a.Value && a.Value.selected);
		if (selectedNode) {
			state = u.updateIn(selectedNode.PathStr_Updeep, u.omit(["selected", "openPanel"]), state);
		}

		//if (action.payload.path == null) return state;
	}

	// if we're focusing a new node, at-root unfocus the old focused node
	if (action.Is(ACTViewCenterChange) && action.payload.mapID == mapID) {
		let nodes = GetTreeNodesInObjTree(state, true);
		let focusNode = nodes.FirstOrX(a=>a.Value && a.Value.focused);
		if (focusNode) {
			state = u.updateIn(focusNode.PathStr_Updeep, u.omit(["focused", "viewOffset"]), state);
		}
	}

	// regular (branching) reducer portion
	// ==========
github Venryx / DebateMap / Source / Store / main / mapViews / $mapView.ts View on Github external
let oldTreeNodes = GetTreeNodesInObjTree(state, true);
		let newTreeNodes = GetTreeNodesInObjTree(action.payload.mapView, true);

		// deselect old selected-node, if a new one's being set
		let oldSelectedNode_treeNode = oldTreeNodes.FirstOrX(a=>a.Value && a.Value.selected);
		let newSelectedNode_treeNode = newTreeNodes.FirstOrX(a=>a.Value && a.Value.selected);
		if (oldSelectedNode_treeNode && newSelectedNode_treeNode) {
			newState = u.updateIn(oldSelectedNode_treeNode.PathStr_Updeep, u.omit(["selected", "openPanel"]), newState);
		}

		// defocus old focused-node, if a new one's being set
		let oldFocusedNode_treeNode = oldTreeNodes.FirstOrX(a=>a.Value && a.Value.focused);
		let newFocusedNode_treeNode = newTreeNodes.FirstOrX(a=>a.Value && a.Value.focused);
		if (oldFocusedNode_treeNode && newFocusedNode_treeNode) {
			newState = u.updateIn(oldFocusedNode_treeNode.PathStr_Updeep, u.omit(["focused", "viewOffset"]), newState);
		}

		let updatePrimitiveTreeNodes = GetTreeNodesInObjTree(action.payload.mapView).filter(a=>IsPrimitive(a.Value) || a.Value == null);
		for (let updatedNode of updatePrimitiveTreeNodes) {
			newState = u.updateIn(updatedNode.PathStr_Updeep, updatedNode.Value, newState);
		}

		return newState;
	}

	let newState = {...state,
		rootNodeViews: RootNodeViewsReducer(state.rootNodeViews, action, mapID),
		bot_currentNodeID: SimpleReducer(`main/mapViews/${mapID}/bot_currentNodeID`)(state.bot_currentNodeID, action),
	};
	if (ShallowChanged(state, newState)) return newState;
github AndersDJohnson / firedux / src / index.js View on Github external
function makeFirebaseState (action, state, path, value, merge = false) {
      // const keyPath = urlToKeyPath(path)
      // const dataPath = 'data.' + keyPath
      const dataPath = ['data'].concat(splitUrl(path))
      // const statusPath = 'status.' + keyPath
      // debug('MAKE FIREBASE STATE FOR ACTION', action.type, 'VALUE', keyPath, value, 'merge', merge)
      value = merge ? value : updeep.constant(value)
      const newState = updeep.updateIn(dataPath, value, state)
      return newState
    }
github kresusapp / kresus / client / store / banks.js View on Github external
function addAccesses(state, pAccesses, accounts, operations) {
    let accesses = pAccesses instanceof Array ? pAccesses : [pAccesses];
    accesses.forEach(access => {
        assert(
            typeof access.id === 'number',
            'The second parameter of addAccesses should have a number id'
        );
    });

    let accessesMapUpdate = {};
    for (let access of accesses) {
        accessesMapUpdate[access.id] = new Access(access, all(state));
    }

    let newState = updateAccessesMap(state, accessesMapUpdate);
    newState = u.updateIn(
        'accessIds',
        getAccessIds(newState).concat(accesses.map(access => access.id)),
        newState
    );

    newState = addAccounts(newState, accounts, operations);

    return sortAccesses(newState);
}

updeep

Easily update nested frozen objects and arrays in a declarative and immutable manner.

MIT
Latest version published 2 years ago

Package Health Score

57 / 100
Full package analysis