Coder Social home page Coder Social logo

janmalch / ngxs-electron-storage Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 994 KB

NGXS storage plugin for Electron, that helps you to persist your store data in files.

JavaScript 14.35% TypeScript 82.49% HTML 2.82% CSS 0.34%
angular angular6 electron ngxs library

ngxs-electron-storage's Introduction

npm version

ngxs-electron-storage

This @NGXS storage plugin helps you to persist your store data in files.

It will persist any changes in your store automatically. It does check for changes and allows debouncing of file writing (see Usage).

More on how storage plugins work: Storage - ngxs.gitbooks.io

Installation

npm i ngxs-electron-storage
@NgModule({
  imports: [
    NgxsModule.forRoot(states),
    NgxsElectronStorageModule.forRoot(),
    NgxsStoragePluginModule.forRoot()
  ],
  providers: [
    {
      provide: STORAGE_ENGINE,
      useClass: ElectronStorageEngine
    }
  ]
})

Usage

You can pass a configuration object in the forRoot method.

interface ElectronStorageOptions {
  fileExtension?: string; // the file extension
  location?: string; // the location to store the files 
  debounce?: number; // you can debounce the IO process of writing the file (in milliseconds)
}
Defaults
{
  debounce: 0, 
  location: "~",
  fileExtension: "json"
}

If your given location starts with a ~ it will be replaced by the userData folder from electron: (electron.app || electron.remote.app).getPath('userData');

So you can write { location: "~/data"} to store your files in %AppData%\Roaming\your-app\data.

The plugin will ensure that the location exists once at the start and creates the directory if necessary.

ElectronStorageService

You can inject a ElectronStorageService in your components to have access to the store objects, which represent your files.

Each store object exposes a persistNotifications$ observable, which emits notifications with the store name and the serialized state. The service itself also exposes a persistNotifications$ observable, which combines all notifications of all stores.

demo

Clone this repository and run npm install && npm run lib-ea.

ngxs-electron-storage's People

Contributors

dependabot[bot] avatar janmalch avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.