fix: to json result

This commit is contained in:
Zixuan Chen 2022-12-07 13:32:15 +08:00
parent 91e7b3ac87
commit b1738e34a9
3 changed files with 11 additions and 2 deletions

View file

@ -66,7 +66,15 @@ Deno.test({name: "sync"}, async (t) => {
text.insert(loro, 0, "hello world");
const loro_bk = new Loro();
loro_bk.import_updates(loro.export_updates());
console.log(loro_bk.to_json())
assertEquals(loro_bk.to_json(), loro.to_json());
const text_bk = loro_bk.getText("text");
assertEquals(text_bk.value, "hello world");
text_bk.insert(loro_bk, 0, "a ");
loro.import_updates(loro_bk.export_updates());
assertEquals(text.value, "a hello world");
const map = loro.getMap("map");
map.set(loro, "key", "value");
console.log(loro.to_json())
})
})

View file

@ -24,6 +24,7 @@ export {
PrelimText,
};
// Extend the interfaces here, to provide richer type information
declare module "./pkg/loro_wasm.js" {
interface Loro {
export_updates(version?: Uint8Array): Uint8Array;

View file

@ -121,7 +121,7 @@ impl Loro {
pub fn to_json(&self) -> JsResult<JsValue> {
let json = self.0.to_json();
Ok(serde_wasm_bindgen::to_value(&json)?)
Ok(json.into())
}
}