Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ngrx-store-manager

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngrx-store-manager

* An implementation of NgRx Facades on Angular 7.2.0. * The purpose behind this library is to enable developers to create dynamic stores with dynamic actions and effects. * All actions results will be saved in the store automatically on success.

  • 0.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

ngrx-store-manager

  • An implementation of NgRx Facades on Angular 7.2.0.
  • The purpose behind this library is to enable developers to create dynamic stores with dynamic actions and effects.
  • All actions results will be saved in the store automatically on success.

Installation

Run npm i ngrx-store-manager --save to install the package.

Configuration

Create a new store.config.ts file with

import { StoreConfig } from 'ngrx-store-manager';
import { AppService } from './app.service';

export const AppConfig: StoreConfig[] = [
    {
        state: 'test',
        initialState: {
            approved: true
        },
        actions: [
            {
                name: 'GET_OTHER',
                service: AppService,
                method: 'getOtherData'
            },
            {
                name: 'SET_OTHER',
                service: AppService,
                method: 'setOtherData'
            }
        ]
    }
];

And in your .module.ts file add StoreManagerModule to the imports of your root module

StorageManagerModule.forRoot(AppConfig)

Or if you are using it in a feature module you can use StorageManagerModule.forChild

  • In the snippet above, we are creating a new store by the name test and we added an initial state for that store
  • We also added two actions, GET and SET which will use two methods from AppService to execute the actions

Facade

Using the facade will be easy from here on, just import the facade into your component file and add it to the constructor

import { StoreFacade } from 'ngrx-store-manager';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
})
export class AppComponent {
    constructor(public store: StoreFacade) { }
}

Facade API

select(storeName: string, sync?: boolean)
  • use it to select data from the store by name.
  • this.store.select('test') will get the store named test synchronously.
  • this.store.select('test', false) will create an observable for the store named test which you can use with the async pipe.
getData(storeName: string, action?: string)
  • use it to dispatch an event without payload to the store.
  • this.store.getData('test') will dispatch a GET event which is the default event for that function.
  • this.store.getData('test', 'GET_OTHER') will dispatch a GET_OTHER event.
  • will return an observable of that store, it will populate only when the action is done (as in an http request), then you can subscribe to that observable to work with the results.
setData(storeName: string, payload: any, action?: string)
  • use it to dispatch an event with a payload to the store.
  • this.store.setData('test', payload) will dispatch a SET event which is the default event for that function.
  • this.store.getData('test', payload, 'SET_OTHER') will dispatch a SET_OTHER event.
  • will return an observable of that store, it will populate only when the action is done (as in an http request), then you can subscribe to that observable to work with the results.

Demo

Please refer to the demo folder or follow this link https://stackblitz.com/edit/ngrx-store-manager-demo

FAQs

Package last updated on 26 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc