How to use the immer.applyPatches function in immer

To help you get started, we’ve selected a few immer 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 axisgroup / RxQ / src / session.js View on Github external
// https://tools.ietf.org/html/rfc6902#page-3
                  // https://tools.ietf.org/html/rfc6901#section-5
                  const arrayPath = patch.path.split("/").filter(s => s !== "");
                  return {
                    ...patch,
                    path: [key, ...arrayPath]
                  };
                });

                return [...acc, ...transformedPatches];
              }, []);
              return {
                ...reqResp,
                response: {
                  ...reqResp.response,
                  result: applyPatches(acc.response.result, patches)
                }
              };
            },
            {
github google / perfetto / ui / src / frontend / index.ts View on Github external
patchState(patches: Patch[]) {
    const oldState = globals.state;
    globals.state = applyPatches(globals.state, patches);

    // If the visible time in the global state has been updated more recently
    // than the visible time handled by the frontend @ 60fps, update it. This
    // typically happens when restoring the state from a permalink.
    globals.frontendLocalState.mergeState(globals.state.frontendLocalState);

    // Only redraw if something other than the frontendLocalState changed.
    for (const key in globals.state) {
      if (key !== 'frontendLocalState' && key !== 'visibleTracks' &&
          oldState[key] !== globals.state[key]) {
        this.redraw();
        return;
      }
    }
  }
github r6db / app / src / renderer / lib / state.ts View on Github external
ipcRenderer.addListener('patch', (_, patches) => {
    appstate = applyPatches(appstate, patches);
    console.trace('patch', patches, appstate);
    notify();
});
github davidkpiano / xstate / packages / xstate-immer / src / index.ts View on Github external
return xstateAssign((context, event) => {
    const [, patches] = event.patches;

    return applyPatches(context, patches);
  });
}
github tuoxiansp / vision / packages / core / src / Data.ts View on Github external
redo() {
        const patches = this.patchesStack[this.hadInversedPatchesStack.length - 1]
        this.inversePatchesStack.unshift(this.hadInversedPatchesStack.shift())
        this.value = applyPatches(this.value, patches)

        return this
    }
github stone-payments / pos-mamba-sdk / packages / pos / simulator / plugins / registry / includes / persistent.js View on Github external
set(fn) {
        if (typeof fn === 'function') {
          const changes = [];
          const persistentData = Registry.persistent.get();

          produce(persistentData, fn, patches => {
            changes.push(...patches);
          });

          localStorage.setItem(
            '_mamba_persistent_',
            JSON.stringify(applyPatches(persistentData, changes)),
          );

          Registry.fire('persistentDataChanged', changes);
        }
      },
    };
github PolymerLabs / actor-boilerplate / src / actors / adapters / preact / index.tsx View on Github external
[PubSubMessageType.PUBLISH](msg: PublishMessage) {
    this.state = applyPatches(this.state, msg.payload as Patch[]);
    this.render(this.state);
  }
github MynockSpit / no-boilerplate-redux / src / default-reducer.js View on Github external
export function nbprReducer(state = {}, { meta, payload }) {
  let returnState = state

  if (meta.nbpr === 'UPDATE') {
    if (state === undefined || state === null) {
      returnState = {}
    }

    returnState = applyPatches(returnState, payload)
  } else if (meta.nbpr === 'REPLACE') {
    returnState = payload
  }

  return returnState
}
github tuoxiansp / vision / packages / core / src / Data.ts View on Github external
undo() {
        const patches = this.inversePatchesStack.shift()
        this.hadInversedPatchesStack.unshift(patches)
        this.value = applyPatches(this.value, patches)

        return this
    }

immer

Create your next immutable state by mutating the current one

MIT
Latest version published 2 months ago

Package Health Score

94 / 100
Full package analysis