mirror of
https://github.com/loro-dev/loro.git
synced 2025-01-23 05:24:51 +00:00
fix: use Object.getPrototypeOf instead of __proto__
This commit is contained in:
parent
aa87a96286
commit
14c66edcd4
4 changed files with 31 additions and 7 deletions
|
@ -128,7 +128,7 @@ export function isContainer(value: any): value is Container {
|
|||
return false;
|
||||
}
|
||||
|
||||
const p = value.__proto__;
|
||||
const p = Object.getPrototypeOf(value);
|
||||
if (p == null || typeof p !== "object" || typeof p["kind"] !== "function") {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
MapDiff,
|
||||
TextDiff,
|
||||
setPanicHook,
|
||||
getType,
|
||||
} from "../src";
|
||||
|
||||
setPanicHook();
|
||||
|
@ -303,8 +304,8 @@ describe("event", () => {
|
|||
let first = true;
|
||||
loro.subscribe((e) => {
|
||||
if (first) {
|
||||
const diff = e.diff.diff;
|
||||
const text = diff[0].insert[0] as LoroText;
|
||||
const diff = (e.diff as ListDiff).diff;
|
||||
const text = diff[0].insert![0] as LoroText;
|
||||
text.insert(0, "abc");
|
||||
first = false;
|
||||
}
|
||||
|
@ -315,6 +316,32 @@ describe("event", () => {
|
|||
expect(loro.toJson().list[0]).toBe('abc');
|
||||
});
|
||||
});
|
||||
|
||||
it("diff can contain containers", async () => {
|
||||
const doc = new Loro();
|
||||
const list = doc.getList("list");
|
||||
let ran = false;
|
||||
doc.subscribe(event => {
|
||||
if (event.diff.type === "list") {
|
||||
for (const item of event.diff.diff) {
|
||||
const t = item.insert![0] as LoroText;
|
||||
expect(t.toString()).toBe("Hello")
|
||||
expect(item.insert?.length).toBe(2);
|
||||
expect(getType(item.insert![0])).toBe("Text")
|
||||
expect(getType(item.insert![1])).toBe("Map")
|
||||
}
|
||||
ran = true;
|
||||
}
|
||||
})
|
||||
|
||||
list.insertContainer(0, "Map");
|
||||
const t = list.insertContainer(0, "Text");
|
||||
t.insert(0, "He");
|
||||
t.insert(2, "llo");
|
||||
doc.commit();
|
||||
await new Promise(resolve => setTimeout(resolve, 1));
|
||||
expect(ran).toBeTruthy()
|
||||
})
|
||||
});
|
||||
|
||||
function oneMs(): Promise<void> {
|
||||
|
|
|
@ -305,7 +305,6 @@ describe("type", () => {
|
|||
it("works for list type", () => {
|
||||
const loro = new Loro<{ list: LoroList<[string, number]> }>();
|
||||
const list = loro.getTypedList("list");
|
||||
console.dir((list as any).__proto__);
|
||||
list.insertTyped(0, "123");
|
||||
list.insertTyped(1, 123);
|
||||
const v0 = list.getTyped(loro, 0);
|
||||
|
@ -331,7 +330,6 @@ describe("tree", () => {
|
|||
it("create move", () => {
|
||||
const id = tree.create();
|
||||
const childID = tree.create(id);
|
||||
console.log(typeof id);
|
||||
assertEquals(tree.parent(childID), id);
|
||||
});
|
||||
|
||||
|
|
|
@ -68,6 +68,5 @@ describe("Version", () => {
|
|||
it("get ops inside changes", () => {
|
||||
const change = a.getOpsInChange({ peer: 0n, counter: 2 });
|
||||
expect(change.length).toBe(1);
|
||||
console.dir(change, { depth: 100 });
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue