How to use object-path-immutable - 10 common examples

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 elastic / kibana / x-pack / plugins / canvas / public / state / reducers / elements.js View on Github external
function assignElementProperties(workpadState, pageId, elementId, props) {
  const pageIndex = getPageIndexById(workpadState, pageId);
  const elementsPath = ['pages', pageIndex, 'elements'];
  const elementIndex = get(workpadState, elementsPath, []).findIndex(
    element => element.id === elementId
  );

  if (pageIndex === -1 || elementIndex === -1) {
    return workpadState;
  }

  // remove any AST value from the element caused by https://github.com/elastic/kibana-canvas/issues/260
  // TODO: remove this after a bit of time
  const cleanWorkpadState = del(workpadState, elementsPath.concat([elementIndex, 'ast']));

  return assign(cleanWorkpadState, elementsPath.concat(elementIndex), props);
}
github elastic / kibana / x-pack / plugins / canvas / public / state / reducers / elements.js View on Github external
function assignElementProperties(workpadState, pageId, elementId, props) {
  const pageIndex = getPageIndexById(workpadState, pageId);
  const elementsPath = ['pages', pageIndex, 'elements'];
  const elementIndex = get(workpadState, elementsPath, []).findIndex(
    element => element.id === elementId
  );

  if (pageIndex === -1 || elementIndex === -1) {
    return workpadState;
  }

  // remove any AST value from the element caused by https://github.com/elastic/kibana-canvas/issues/260
  // TODO: remove this after a bit of time
  const cleanWorkpadState = del(workpadState, elementsPath.concat([elementIndex, 'ast']));

  return assign(cleanWorkpadState, elementsPath.concat(elementIndex), props);
}
github elastic / kibana / x-pack / plugins / canvas / public / state / reducers / pages.js View on Github external
const pageIndex = getPageIndexById(workpadState, id);
      const newIndex = pageIndex + position;

      // TODO: do something better when given an invalid page id
      if (pageIndex < 0) {
        return workpadState;
      }

      // don't move pages past the first or last position
      if (newIndex < 0 || newIndex >= workpadState.pages.length) {
        return workpadState;
      }

      // remove and re-insert the page
      const page = { ...workpadState.pages[pageIndex] };
      let newState = insert(del(workpadState, `pages.${pageIndex}`), 'pages', page, newIndex);

      // adjust the selected page index and return the new state
      const selectedId = workpadState.pages[workpadState.page].id;
      const newSelectedIndex = newState.pages.findIndex(page => page.id === selectedId);
      newState = set(newState, 'page', newSelectedIndex);

      // changes to the page require navigation
      const router = routerProvider();
      router.navigateTo('loadWorkpad', { id: newState.id, page: newState.page + 1 });

      return newState;
    },
github arthurgallo / reducerless-redux / __tests__ / reducerless.js View on Github external
        update: state => im.set(state, 'hello', 'kitty'),
      });
github cantierecreativo / redux-bees / src / reducers / requests.js View on Github external
let newState = state;

    if (action.payload.body) {
      const { data, meta } = action.payload.body;

      let normalizedData;

      if (Array.isArray(data)) {
        normalizedData = data.map(record => ({ id: record.id, type: record.type }));
      } else if (data && data.id) {
        normalizedData = { id: data.id, type: data.type };
      } else {
        normalizedData = null;
      }

      newState = immutable.set(
        newState,
        [name, JSON.stringify(params), 'response'],
        normalizedData,
      );

      if (meta) {
        newState = immutable.set(
          newState,
          [name, JSON.stringify(params), 'meta'],
          meta
        );
      }
    }

    newState = immutable.set(
      newState,
github cantierecreativo / redux-bees / src / reducers / requests.js View on Github external
const invalidate = (state, actionName, key) => (
  immutable.set(state, [actionName, key, 'invalid'], true)
);
github cantierecreativo / redux-bees / src / reducers / requests.js View on Github external
newState,
      [name, JSON.stringify(params), 'isLoading'],
      false,
    );

    return newState;
  } else if (metaType === 'error') {
    let newState = state;

    newState = immutable.set(
      newState,
      [name, JSON.stringify(params), 'isLoading'],
      false,
    );

    newState = immutable.set(
      newState,
      [name, JSON.stringify(params), 'response'],
      null,
    );

    if (action.payload instanceof Error) {

      newState = immutable.set(
        newState,
        [name, JSON.stringify(params), 'error'],
        action.payload.message
      );

      newState = immutable.del(
        newState,
        [name, JSON.stringify(params), 'headers'],
github elastic / kibana / x-pack / plugins / canvas / public / state / reducers / transient.js View on Github external
[transientActions.setFirstLoad]: (transientState, { payload }) => {
      return set(transientState, 'isFirstLoad', Boolean(payload));
    },
github htmlburger / carbon-fields / assets / js / fields / reducer.js View on Github external
	[switchComplexTab]: (state, { payload: { fieldId, groupId } }) => immutable.set(state, `${fieldId}.ui.current_tab`, groupId),
}, {}));
github elastic / kibana / x-pack / plugins / canvas / public / state / reducers / pages.js View on Github external
[actions.stylePage]: (workpadState, { payload }) => {
      const pageIndex = workpadState.pages.findIndex(page => page.id === payload.pageId);
      return set(workpadState, ['pages', pageIndex, 'style'], payload.style);
    },

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