npm.io
0.5.3 • Published 1 year ago

@k8slens/electron-sync-store

Licence
MIT
Version
0.5.3
Deps
3
Size
67 kB
Vulns
0
Weekly
0
Install scriptsThis package runs scripts during installation (preinstall/install/postinstall)

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