(preOperation: IOperation, curOperation: IOperation)
| 47 | } |
| 48 | |
| 49 | export 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 | } |
no test coverage detected