Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: find id spans between #607

Merged
merged 8 commits into from
Jan 6, 2025
Merged

feat: find id spans between #607

merged 8 commits into from
Jan 6, 2025

Conversation

zxch3n
Copy link
Member

@zxch3n zxch3n commented Jan 5, 2025

Now you can now inspect all the changes that happened in an event:

const docA = new LoroDoc();
docA.setPeerId("1");
const docB = new LoroDoc();

docA.getText("text").update("Hello");
docA.commit();
const snapshot = docA.export({ mode: "snapshot" });
let done = false;
docB.subscribe(e => {
  const spans = docB.findIdSpansBetween(e.from, e.to);
  expect(spans.retreat).toHaveLength(0);
  expect(spans.forward).toHaveLength(1);
  expect(spans.forward[0]).toEqual({
    peer: "1",
    counter: 0,
    length: 5,
  });
  const changes = docB.exportJsonInIdSpan(spans.forward[0]);
  expect(changes).toStrictEqual([{
    id: "0@1",
    timestamp: expect.any(Number),
    deps: [],
    lamport: 0,
    msg: undefined,
    ops: [{
      container: "cid:root-text:Text",
      counter: 0,
      content: {
        type: "insert",
        pos: 0,
        text: "Hello"
      }
    }]
  }]);
  done = true;
});
docB.import(snapshot);
await Promise.resolve();
expect(done).toBe(true);

@zxch3n zxch3n requested a review from Leeeon233 January 5, 2025 10:49
@zxch3n zxch3n merged commit 8039e44 into main Jan 6, 2025
1 check passed
@zxch3n zxch3n deleted the feat-find-path branch January 6, 2025 03:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants