refactor: snapshot store to diff (#3155)
* refactor: snapshot store to diff * change initial state position * fix old snapshot format * encapsulate json diff
This commit is contained in:
20
projects/app/src/web/core/app/diff.ts
Normal file
20
projects/app/src/web/core/app/diff.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { create } from 'jsondiffpatch';
|
||||
|
||||
const createWorkflowDiffPatcher = () =>
|
||||
create({
|
||||
objectHash: (obj: any) => obj.id || obj.nodeId || obj._id,
|
||||
propertyFilter: (name: string) => name !== 'selected'
|
||||
});
|
||||
|
||||
const diffPatcher = createWorkflowDiffPatcher();
|
||||
|
||||
export const createDiff = <T extends Record<string, unknown>>(initialState?: T, newState?: T) => {
|
||||
return diffPatcher.diff(initialState, newState);
|
||||
};
|
||||
|
||||
export const applyDiff = <T extends Record<string, unknown>>(
|
||||
initialState?: T,
|
||||
diff?: ReturnType<typeof diffPatcher.diff>
|
||||
) => {
|
||||
return diffPatcher.patch(structuredClone(initialState), diff) as T;
|
||||
};
|
||||
@@ -631,3 +631,14 @@ export const compareSnapshot = (
|
||||
|
||||
return isEqual(node1, node2);
|
||||
};
|
||||
|
||||
// remove node size
|
||||
export const simplifyNodes = (nodes: Node[]) => {
|
||||
return nodes.map((node) => ({
|
||||
id: node.id,
|
||||
type: node.type,
|
||||
position: node.position,
|
||||
data: node.data,
|
||||
zIndex: node.zIndex
|
||||
}));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user