Skip to content

Commit

Permalink
feat(presence): Support for arbitrary data
Browse files Browse the repository at this point in the history
  • Loading branch information
Calyhre committed Oct 22, 2020
1 parent f01b8b6 commit 607d42f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/json1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,11 +735,11 @@ function transformPresence(presence: Presence | null, op: JSONOp, isOwnOperation
const end = transformPosition(presence.end, op)

if (start && end) {
return { start, end }
return { ...presence, start, end }
} else if (start) {
return { start, end: start }
return { ...presence, start, end: start }
} else if (end) {
return { start: end, end }
return { ...presence, start: end, end }
}

return null
Expand Down
9 changes: 9 additions & 0 deletions test/presence.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,13 @@ describe("presences", () => {
presenceAfter
);
});

it("allows arbitrary data in presences", () => {
const op = ["z", 0, { i: "hello" }];
const data = { user: "John Doe", color: "blue" };
const presenceBefore = { start: ["z", 0], end: ["z", 1], data };
const presenceAfter = type.transformPresence(presenceBefore, op);

assert.ok(presenceBefore.data === presenceAfter.data);
});
});

0 comments on commit 607d42f

Please sign in to comment.