MCPcopy Create free account
hub / github.com/apitable/apitable / composeOperation

Function composeOperation

packages/core/src/engine/ot/compose.ts:49–75  ·  view source on GitHub ↗
(preOperation: IOperation, curOperation: IOperation)

Source from the content-addressed store, hash-verified

47}
48
49export function composeOperation(preOperation: IOperation, curOperation: IOperation): { operation: IOperation | null; isComposed: boolean } {
50 if (
51 curOperation.actions.length === preOperation.actions.length &&
52 curOperation.actions.length === 1 &&
53 preOperation.actions[0]!.p.length === curOperation.actions[0]!.p.length
54 ) {
55 // filter the same actions as od, oi or li, ld
56 const actions = jot.compose(curOperation.actions, preOperation.actions).filter((action: any) => {
57 if (action.n === OTActionName.ObjectReplace) {
58 return !isEqual(action.od, action.oi);
59 }
60 if (action.n === OTActionName.ListReplace) {
61 return !isEqual(action.ld, action.li);
62 }
63 return true;
64 });
65 // The merged actions do not exceed the length of the original actions
66 if (actions.length <= curOperation.actions.length) {
67 let operation: IOperation | null = null;
68 if (actions.length > 0) {
69 operation = { ...curOperation, actions };
70 }
71 return { operation, isComposed: true };
72 }
73 }
74 return { operation: curOperation, isComposed: false };
75}

Callers 2

composeChangesetMethod · 0.90
composeOperationsFunction · 0.85

Calls 1

filterMethod · 0.45

Tested by

no test coverage detected