npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngrx-store-localstorage-replace

v0.1.5

Published

State and local storage syncing for @ngrx/store

Downloads

11

Readme

ngrx-store-localstorage

Simple syncing between ngrx store and local storage

Dependencies

ngrx-store-localstorage depends on @ngrx/store and Angular 2.

Usage

npm install ngrx-store-localstorage --save
  1. Import compose and combineReducers from @ngrx/store and @ngrx/core/compose
  2. Invoke the localStorageSync function after combineReducers, specifying the slices of state you would like to keep synced with local storage.
  3. Optionally specify whether to rehydrate this state from local storage as initialState on application bootstrap.
  4. Invoke composed function with application reducers as an argument to StoreModule.provideStore.
import { Store, StoreModule } from '@ngrx/store';
import { todos, visibilityFilter } from './reducers';
import { NgModule } from '@angular/core'

@NgModule({
  imports: [
    BrowserModule,
    StoreModule.provideStore(
        compose(
            localStorageSync(['todos']),
            combineReducers
        )({todos, visibilityFilter})
    )
  ]
})
export class MyAppModule {}

API

localStorageSync(keys : any[], rehydrateState : boolean = false, storage: Storage = localStorage) : Reducer

Provide state (reducer) keys to sync with local storage. Optionally specify whether to rehydrate initialState from local storage on bootstrap. Returns a meta-reducer

Arguments

  • keys State keys to sync with local storage. The keys can be defined in two different formats:

    • (string[]): array of strings representing the state (reducer) keys. Full state will be synced (e.g. localStorageSync(['todos'])).

    • (object[]): Array of objects where for each object the key represents the state key and the value represents custom serialize/deserialize options. This can be one of the following:

      • an array of properties which should be synced. This allows for the partial state sync (e.g. localStorageSync([{todos: ['name', 'status'] }, ... ]))

      • a reviver function as specified in the JSON.parse documentation

      • an object with properties that specify one or more of the following:

        • serialize: a function that takes a state object and returns a plain json object to pass to json.stringify

        • deserialize: a function that takes that takes the raw JSON from JSON.parse and builds a state object

        • replacer: a replacer function as specified in the JSON.stringify documentation

        • space: the space value to pass JSON.stringify

        • reviver: a reviver function as specified in the JSON.parse documentation

        • filter: an array of properties which should be synced (same format as the stand-along array specified above)

  • rehydrateState (boolean? = false): Pull initial state from local storage on startup

  • storage (Storage? = localStorage): Specify an object that conforms to the Storage interface to use, this will default localStorage