mirror of
https://github.com/loro-dev/loro.git
synced 2025-01-23 13:39:12 +00:00
fix: not leaking closure
This commit is contained in:
parent
63ebbe2ddb
commit
b0d7ad88b9
2 changed files with 8 additions and 5 deletions
|
@ -1,5 +1,4 @@
|
||||||
import init, {
|
import init, {
|
||||||
enableDebug,
|
|
||||||
Loro,
|
Loro,
|
||||||
LoroMap,
|
LoroMap,
|
||||||
PrelimList,
|
PrelimList,
|
||||||
|
@ -15,7 +14,6 @@ import {
|
||||||
|
|
||||||
await init();
|
await init();
|
||||||
setPanicHook();
|
setPanicHook();
|
||||||
enableDebug();
|
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "loro_wasm",
|
name: "loro_wasm",
|
||||||
|
|
|
@ -6,7 +6,7 @@ use loro_internal::{
|
||||||
log_store::GcConfig,
|
log_store::GcConfig,
|
||||||
ContainerType, List, LoroCore, Map, Origin, Text, Transact, TransactionWrap, VersionVector,
|
ContainerType, List, LoroCore, Map, Origin, Text, Transact, TransactionWrap, VersionVector,
|
||||||
};
|
};
|
||||||
use std::{cell::RefCell, ops::Deref, sync::Arc};
|
use std::{cell::RefCell, ops::Deref, rc::Rc, sync::Arc};
|
||||||
use wasm_bindgen::{__rt::RefMut, prelude::*};
|
use wasm_bindgen::{__rt::RefMut, prelude::*};
|
||||||
mod log;
|
mod log;
|
||||||
mod prelim;
|
mod prelim;
|
||||||
|
@ -223,7 +223,10 @@ impl Loro {
|
||||||
self.0.borrow_mut().subscribe_deep(Box::new(move |e| {
|
self.0.borrow_mut().subscribe_deep(Box::new(move |e| {
|
||||||
let promise = Promise::resolve(&JsValue::NULL);
|
let promise = Promise::resolve(&JsValue::NULL);
|
||||||
let ob = observer.clone();
|
let ob = observer.clone();
|
||||||
let closure = Closure::new(move |_: JsValue| {
|
type C = Closure<dyn FnMut(JsValue)>;
|
||||||
|
let drop_handler: Rc<RefCell<Option<C>>> = Rc::new(RefCell::new(None));
|
||||||
|
let copy = drop_handler.clone();
|
||||||
|
let closure = Closure::once(move |_: JsValue| {
|
||||||
ob.call1(
|
ob.call1(
|
||||||
&Event {
|
&Event {
|
||||||
local: e.local,
|
local: e.local,
|
||||||
|
@ -231,9 +234,11 @@ impl Loro {
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
drop(copy);
|
||||||
});
|
});
|
||||||
let _ = promise.then(&closure);
|
let _ = promise.then(&closure);
|
||||||
closure.forget();
|
drop_handler.borrow_mut().replace(closure);
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue