Skip to content

Commit

Permalink
Add function to forget callbacks of database (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
devashishdxt authored Aug 12, 2024
1 parent 11e15ae commit 3a91b3e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,33 @@ impl Database {
.set_onversionchange(Some(closure.as_ref().unchecked_ref()));
self.version_change_callback = Some(closure);
}

/// Release memory management of the callbacks to JS GC.
///
/// > Note: This may leak memory. Read more about it
/// > [here](https://docs.rs/wasm-bindgen/latest/wasm_bindgen/closure/struct.Closure.html#method.into_js_value).
pub fn forget_callbacks(&mut self) {
let abort_callback = self.abort_callback.take();
let close_callback = self.close_callback.take();
let error_callback = self.error_callback.take();
let version_change_callback = self.version_change_callback.take();

if let Some(callback) = abort_callback {
callback.forget();
}

if let Some(callback) = close_callback {
callback.forget();
}

if let Some(callback) = error_callback {
callback.forget();
}

if let Some(callback) = version_change_callback {
callback.forget();
}
}
}

impl TryFrom<EventTarget> for Database {
Expand Down

0 comments on commit 3a91b3e

Please sign in to comment.