How to use the object-path-immutable.push function in object-path-immutable

To help you get started, we’ve selected a few object-path-immutable 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 redux-json-api / redux-json-api / src / state-mutation.js View on Github external
if (typeof resource !== 'object') {
    return state;
  }

  let newState = state;
  const updatePath = [resource.type, 'data'];

  if (stateContainsResource(state, resource)) {
    const resources = state[resource.type].data;
    const idx = resources.findIndex(item => item.id === resource.id);

    if (!equal(resources[idx], resource)) {
      newState = imm.set(newState, updatePath.concat(idx), resource);
    }
  } else {
    newState = imm.push(newState, updatePath, resource);
  }

  const rels = resource.relationships;

  if (!rels) {
    return newState;
  }

  Object.keys(rels).forEach(relKey => {
    if (!hasOwnProperties(rels[relKey], ['data', 'type'])) {
      return;
    }

    const entityPath = [rels[relKey].data.type, 'data'];

    if (!hasOwnProperties(newState, entityPath)) {
github Automattic / woocommerce-services / client / apps / settings / state / values / reducer.js View on Github external
reducers[ ADD_ARRAY_FIELD_ITEM ] = ( state, action ) => {
	return objectPath.push( state, action.path, action.item );
};
github htmlburger / carbon-fields / assets / js / fields / reducer.js View on Github external
[enableComplexGroupType]: (state, { payload: { fieldId, groupName } }) => {
		const index = findIndex(state[fieldId].enabledGroupTypes, groupName);

		return immutable.push(state, `${fieldId}.enabledGroupTypes`, groupName);
	},
github elastic / kibana / x-pack / plugins / canvas / public / state / reducers / elements.js View on Github external
[actions.duplicateElement]: (workpadState, { payload: { pageId, element } }) => {
      const pageIndex = getPageIndexById(workpadState, pageId);
      if (pageIndex < 0) {
        return workpadState;
      }

      return push(workpadState, ['pages', pageIndex, 'elements'], element);
    },
    [actions.removeElements]: (workpadState, { payload: { pageId, elementIds } }) => {

object-path-immutable

Modify deep object properties without modifying the original object (immutability). Works great with React and Redux.

MIT
Latest version published 3 years ago

Package Health Score

53 / 100
Full package analysis