Skip to content

docs(store): reload merges the value #2843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion plugins/store/guest-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,12 @@ interface IStore {
*
* This method is useful if the on-disk state was edited by the user and you want to synchronize the changes.
*
* Note: This method does not emit change events.
* Note:
* - This method loads the data and merges it with the current store,
* call {@linkcode clear} or {@linkcode reset} first for the store to fully match the on-disk state
* (be careful with the auto save settings as they both trigger that)
* - This method does not emit change events.
*
* @returns
*/
reload(): Promise<void>
Expand Down
8 changes: 8 additions & 0 deletions plugins/store/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ impl<R: Runtime> StoreInner<R> {
}

/// Update the store from the on-disk state
///
/// Note: This method loads the data and merges it with the current store
pub fn load(&mut self) -> crate::Result<()> {
let bytes = fs::read(&self.path)?;

Expand Down Expand Up @@ -499,6 +501,12 @@ impl<R: Runtime> Store<R> {
}

/// Update the store from the on-disk state
///
/// Note:
/// - This method loads the data and merges it with the current store,
/// call [`clear`](Self::clear) or [`reset`](Self::reset) first for the store to fully match the on-disk state
/// (be careful with the auto save settings as they both trigger that)
/// - This method does not emit change events
pub fn reload(&self) -> crate::Result<()> {
self.store.lock().unwrap().load()
}
Expand Down
Loading