Electron Sync Store
npm install @k8slens/electron-sync-storeStore 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:
``ts
import { ElectronSyncStore, modelUpdateEventName } from "electron-sync-store";
// Note: 'store-name' must be unique
const store = ElectronSyncStore.initialize
// Listen to model changes
store.events.on(modelUpdateEventName, model => {
//
});
// After you're done with the store:
store.dispose();
``
* 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
Copyright (c) 2022 Mirantis, Inc.
Licensed under the MIT license.