Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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)
}
};
},
{
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;
}
}
}
ipcRenderer.addListener('patch', (_, patches) => {
appstate = applyPatches(appstate, patches);
console.trace('patch', patches, appstate);
notify();
});
return xstateAssign((context, event) => {
const [, patches] = event.patches;
return applyPatches(context, patches);
});
}
redo() {
const patches = this.patchesStack[this.hadInversedPatchesStack.length - 1]
this.inversePatchesStack.unshift(this.hadInversedPatchesStack.shift())
this.value = applyPatches(this.value, patches)
return this
}
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);
}
},
};
[PubSubMessageType.PUBLISH](msg: PublishMessage) {
this.state = applyPatches(this.state, msg.payload as Patch[]);
this.render(this.state);
}
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
}
undo() {
const patches = this.inversePatchesStack.shift()
this.hadInversedPatchesStack.unshift(patches)
this.value = applyPatches(this.value, patches)
return this
}