Skip to content

Commit

Permalink
Use better type for move patch operation
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriLojda committed Apr 16, 2024
1 parent 7b6eb50 commit 073f3b0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/modules/sync/diff/combinators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ export const makeArrayHandler = <Entity>(
{
op: "move" as const,
path: `/codename:${getCodename(targetOnOtherIndex)}`,
[sourceValue[i - 1] ? "after" : "before"]: { codename: neighbourCodename },
...sourceValue[i - 1]
? { after: { codename: neighbourCodename } }
: { before: { codename: neighbourCodename } },
},
],
...createUpdateOps(v, targetOnOtherIndex)
Expand Down
13 changes: 7 additions & 6 deletions src/modules/sync/types/diffModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ export type PatchOperation =
value: unknown;
oldValue: unknown;
}>
| Readonly<{
op: "move";
path: string;
before?: { codename: string };
after?: { codename: string };
}>;
| (
& Readonly<{
op: "move";
path: string;
}>
& ({ readonly before: { readonly codename: string } } | { readonly after: { readonly codename: string } })
);

0 comments on commit 073f3b0

Please sign in to comment.