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: get pending ops from current txn as json #676

Merged
merged 4 commits into from
Mar 3, 2025

Conversation

YngNs
Copy link
Contributor

@YngNs YngNs commented Mar 3, 2025

resolve #664

Example

  const doc = new LoroDoc();
  doc.setPeerId("1");
  expect(doc.getUncommittedOpsAsJson()).toBeUndefined();
  const text = doc.getText("text");
  text.insert(0, "Hello");
  const pendingOps = doc.getUncommittedOpsAsJson()
  expect(pendingOps).toBeDefined();
  expect(JSON.stringify(pendingOps)).toContain("insert");
  expect(JSON.stringify(pendingOps)).toContain("Hello");
  expect(pendingOps).toEqual({
    "peers": undefined,
    "schema_version": 1,
    "start_version": {},
    changes: [{
      "id": "0@1",
      "deps": [],
      "msg": undefined,
      "lamport": 0,
      "ops": [
        {
          "container": "cid:root-text:Text",
          "counter": 0,
          "content": {
            "type": "insert",
            "pos": 0,
            "text": "Hello"
          }
        }
      ],
      "timestamp": 0,
    }],
  })

@zxch3n zxch3n requested a review from Leeeon233 March 3, 2025 11:55
@zxch3n zxch3n merged commit 4cb7ae3 into loro-dev:main Mar 3, 2025
1 check passed
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.

getJsonUpdates from the current transaction
3 participants