Skip to content

Commit

Permalink
feat(crdt-loro): add missing crdt types (#850)
Browse files Browse the repository at this point in the history
  • Loading branch information
pluvrt authored Jan 12, 2025
1 parent a7051ac commit 5dc8fb9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/crdt-loro/src/loro.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export { CrdtLoroDoc, doc } from "./doc";
export { list } from "./list";
export { map } from "./map";
export { movableList } from "./movableList";
export { object } from "./object";
export { text } from "./text";
export { tree } from "./tree";
export type { LoroType } from "./types";
export const kind = "loro" as const;
13 changes: 13 additions & 0 deletions packages/crdt-loro/src/movableList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Container } from "loro-crdt";
import { isContainer, LoroMovableList } from "loro-crdt";
import type { LoroType } from "./types";

export const movableList = <T extends unknown>(value: T[] | readonly T[] = []) => {
const container = new LoroMovableList();

value.forEach((item, i) => {
isContainer(item) ? container.insertContainer(i, item) : container.insert(i, item as Exclude<T, Container>);
});

return container as unknown as LoroType<LoroMovableList<T>, T[]>;
};
7 changes: 7 additions & 0 deletions packages/crdt-loro/src/tree.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { LoroTree } from "loro-crdt";

export const tree = <T extends Record<string, unknown>>() => {
const container = new LoroTree<T>();

return container;
};

0 comments on commit 5dc8fb9

Please sign in to comment.