@k8slens/electron-sync-store
v0.5.2
Published
Electron Sync Store
Downloads
1,766
Readme
electron-sync-store
Store and load JSON-serialized data to a file in electron. Supports both main and renderer. Files are written atomically.
Inspired by conf
, electron-store
and BaseStore
of OpenLens.
Benefits:
- async operations
- increased performance
In race condition of multiple writes the saved file is arbitrary.
Usage:
import { ElectronSyncStore, modelUpdateEventName } from "electron-sync-store";
// Note: 'store-name' must be unique
const store = ElectronSyncStore.initialize<Model>("store-name", defaultModel, "store.json", /* options */);
// Listen to model changes
store.events.on(modelUpdateEventName, model => {
//
});
// After you're done with the store:
store.dispose();
Architecture
- Main and renderer instances load initial mode from file
- Main instances save model updates to the file and broadcast the update to renderer and other main instances
- Renderer will broadcast model updates to main, which will save the change and broadcast the update again
License
Copyright (c) 2022 Mirantis, Inc.
Licensed under the MIT license. https://opensource.org/licenses/MIT