Skip to content

Commit

Permalink
Refactor: merge two js packages (#532)
Browse files Browse the repository at this point in the history
* feat: make vitest tests pass

* chore: update readme & add deno test for web bundle

* chore: bump version to 1.0.8-alpha.0

* chore: bump loro-crdt version

* fix: build script
export init method from loro-wasm/web

* chore: bump version

* chore: specify which files to include for npm publish

* refactor: rename loro-js to loro-js-test

* refactor: remove the old loro-js folder

* fix: build scripts

* chore: 1.0.8-alpha.3

* chore: add release info
  • Loading branch information
zxch3n authored Oct 29, 2024
1 parent e2be56b commit 62a3a93
Show file tree
Hide file tree
Showing 55 changed files with 1,613 additions and 4,033 deletions.
7 changes: 1 addition & 6 deletions .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
"changelog": "@changesets/changelog-git",
"commit": false,
"fixed": [],
"linked": [
[
"loro-wasm",
"loro-crdt"
]
],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
Expand Down
5 changes: 5 additions & 0 deletions .changeset/wise-balloons-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"loro-crdt": patch
---

Merge two js packages
4 changes: 2 additions & 2 deletions crates/loro-wasm/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ src/
wasm-size/
web-test/
pkg/
web/
scripts/
.cargo/
CHANGELOG.md
Cargo.toml
deno.lock
rollup.config.mjs
tsconfig.json
24 changes: 24 additions & 0 deletions crates/loro-wasm/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# Changelog

## 1.0.8-alpha.3

### Patch Changes

- Fix build for bundler

## 1.0.8-alpha.2

### Patch Changes

- Fix build script for web target

## 1.0.8-alpha.1

### Patch Changes

- Include the build for web

## 1.0.8-alpha.0

### Patch Changes

- Refactor simplify js binding

## 1.0.7

### Patch Changes
Expand Down
105 changes: 55 additions & 50 deletions crates/loro-wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
</p>


https://github.com/loro-dev/loro/assets/18425020/fe246c47-a120-44b3-91d4-1e7232a5b4ac
<h4 align="center">
✨ Loro 1.0 is out! Read the <a href="https://loro.dev/blog/v1.0">announcement</a>.
</h4>

Loro is a [CRDTs(Conflict-free Replicated Data Types)](https://crdt.tech/) library that makes building [local-first apps][local-first] easier. It is currently available for JavaScript (via WASM) and Rust developers.

Explore our vision in our blog: [**✨ Reimagine State Management with CRDTs**](https://loro.dev/blog/loro-now-open-source).
Loro is a [CRDTs(Conflict-free Replicated Data Types)](https://crdt.tech/) library that makes building [local-first apps][local-first] easier. It is currently available for JavaScript (via WASM) and Rust developers.

# Features

Expand All @@ -65,59 +65,64 @@ Explore our vision in our blog: [**✨ Reimagine State Management with CRDTs**](

**Advanced Features in Loro**

- 📖 Preserve Editing History in a [Replayable Event Graph](https://loro.dev/docs/advanced/replayable_event_graph)
- ⏱️ Fast [Time Travel](https://loro.dev/docs/tutorial/time_travel) Through History
- 🏛️ [Version Control with Real-Time Collaboration](https://loro.dev/blog/v1.0#version-control)
- 📦 [Shallow Snapshot](https://loro.dev/docs/advanced/shallow_snapshot) that Works like Git Shallow Clone


https://github.com/loro-dev/loro/assets/18425020/ec2d20a3-3d8c-4483-a601-b200243c9792
> In this example, we demonstrate importing an entire Loro codebase into a Loro-powered
> version controller, preserving the complete Git DAG history while enabling fast version switching.
# Example

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/edit/loro-basic-test?file=test%2Floro-sync.test.ts)

```ts
import { expect, test } from 'vitest';
import { Loro, LoroList } from 'loro-crdt';

/**
* Demonstrates synchronization of two documents with two rounds of exchanges.
*/
// Initialize document A
const docA = new Loro();
const listA: LoroList = docA.getList('list');
listA.insert(0, 'A');
listA.insert(1, 'B');
listA.insert(2, 'C');

// Export the state of document A as a byte array
const bytes: Uint8Array = docA.exportFrom();

// Simulate sending `bytes` across the network to another peer, B
const docB = new Loro();
// Peer B imports the updates from A
docB.import(bytes);

// Verify that B's state matches A's state
expect(docB.toJSON()).toStrictEqual({
list: ['A', 'B', 'C'],
});

// Get the current operation log version of document B
const version = docB.oplogVersion();

// Simulate editing at B: delete item 'B'
const listB: LoroList = docB.getList('list');
listB.delete(1, 1);

// Export the updates from B since the last synchronization point
const bytesB: Uint8Array = docB.exportFrom(version);

// Simulate sending `bytesB` back across the network to A
// A imports the updates from B
docA.import(bytesB);

// Verify that the list at A now matches the list at B after merging
expect(docA.toJSON()).toStrictEqual({
list: ['A', 'C'],
import { LoroDoc, LoroList } from 'loro-crdt';

test('sync example', () => {
/**
* Demonstrates synchronization of two documents with two rounds of exchanges.
*/
// Initialize document A
const docA = new LoroDoc();
const listA: LoroList = docA.getList('list');
listA.insert(0, 'A');
listA.insert(1, 'B');
listA.insert(2, 'C');

// Export the state of document A as a byte array
const bytes: Uint8Array = docA.export({ mode: 'update' });

// Simulate sending `bytes` across the network to another peer, B
const docB = new LoroDoc();
// Peer B imports the updates from A
docB.import(bytes);

// Verify that B's state matches A's state
expect(docB.toJSON()).toStrictEqual({
list: ['A', 'B', 'C'],
});

// Get the current operation log version of document B
const version = docB.oplogVersion();

// Simulate editing at B: delete item 'B'
const listB: LoroList = docB.getList('list');
listB.delete(1, 1);

// Export the updates from B since the last synchronization point
const bytesB: Uint8Array = docB.export({ mode: 'update', from: version });

// Simulate sending `bytesB` back across the network to A
// A imports the updates from B
docA.import(bytesB);

// Verify that the list at A now matches the list at B after merging
expect(docA.toJSON()).toStrictEqual({
list: ['A', 'C'],
});
});
```

Expand All @@ -126,9 +131,9 @@ expect(docA.toJSON()).toStrictEqual({
Loro draws inspiration from the innovative work of the following projects and individuals:

- [Ink & Switch](https://inkandswitch.com/): The principles of Local-first Software have greatly influenced this project. The [Peritext](https://www.inkandswitch.com/peritext/) project has also shaped our approach to rich text CRDTs.
- [Diamond-types](https://github.com/josephg/diamond-types): The [Replayable Event Graph (REG)](https://loro.dev/docs/advanced/replayable_event_graph) algorithm from @josephg has been adapted to reduce the computation and space usage of CRDTs.
- [Diamond-types](https://github.com/josephg/diamond-types): The [Event Graph Walker (Eg-walker)](https://loro.dev/docs/advanced/event_graph_walker) algorithm from @josephg has been adapted to reduce the computation and space usage of CRDTs.
- [Automerge](https://github.com/automerge/automerge): Their use of columnar encoding for CRDTs has informed our strategies for efficient data encoding.
- [Yjs](https://github.com/yjs/yjs): We have incorporated a similar algorithm for effectively merging collaborative editing operations, thanks to their pioneering works.
- [Yjs](https://github.com/yjs/yjs): We have incorporated a similar algorithm for effectively merging collaborative editing operations, thanks to their pioneering work.
- [Matthew Weidner](https://mattweidner.com/): His work on the [Fugue](https://arxiv.org/abs/2305.00583) algorithm has been invaluable, enhancing our text editing capabilities.
- [Martin Kleppmann](https://martin.kleppmann.com/): His work on CRDTs has significantly influenced our comprehension of the field.

Expand Down
84 changes: 82 additions & 2 deletions crates/loro-wasm/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/loro-wasm/deno_tests/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"deno.enable": true
}
10 changes: 10 additions & 0 deletions crates/loro-wasm/deno_tests/basic.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import init, { initSync, LoroDoc } from "../web/loro_wasm.js";
import { expect } from "npm:expect";

await init();

Deno.test("basic", () => {
const doc = new LoroDoc();
doc.getText("text").insert(0, "Hello, world!");
expect(doc.getText("text").toString()).toBe("Hello, world!");
});
3 changes: 3 additions & 0 deletions crates/loro-wasm/deno_tests/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"nodeModulesDir": "auto"
}
Loading

0 comments on commit 62a3a93

Please sign in to comment.