@k8slens/electron-sync-store
TypeScript icon, indicating that this package has built-in type declarations

0.5.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @k8slens/electron-sync-store

Weekly Downloads

600

Version

0.5.0

License

MIT

Unpacked Size

67.5 kB

Total Files

72

Last publish

Collaborators

  • mirantis_it
  • jakolehm
  • k8slens-bot