ngrxstoredata

2.0.0 • Public • Published

store data using ngrx(redux)

A ngrx store implementation port to use with Angular 7 without the use of local storage

This module works with angular 7.x

Installation

npm install --save ngrxstoredata

Usage

Module:

Import StoreModule from @ngrx/store Import reducers from ngrxstoredata/store/reducers

import { StoreModule } from '@ngrx/store';
import {reducers} from 'ngrxstoredata/store/reducers';
 
@NgModule({
  imports: [ StoreModule.forRoot(reducers) ]
})

Component

  1. Component 1
import { Store } from '@ngrx/store';
import * as fromRoot from 'ngrxstoredata/store';
 
export class LoginComponent {
  constructor(private store: Store<fromRoot.AppState>,) {
  }
 
  doLogin(): void {
    // after successfully login or when you wnat to store data
    let data = {name:'vashram', token: 'xxxxx'}
    this.store.dispatch(new fromRoot.SaveDataAction(data));
  }
}
 
  1. Component 2
import { Store } from '@ngrx/store';
import * as fromRoot from 'ngrxstoredata/store/reducers';
import * as fromSave from 'ngrxstoredata/store/reducers/save.reducer';
import { Observable } from 'rxjs/Observable';
 
export class HomeComponent {
  public saveData$: Observable<fromSave.SaveDataState>;
  constructor(private store: Store<fromRoot.AppState>) {
    this.saveData$ = this.store.select('savedata');
  }
 
  getData(): void {
    this.saveData$.subscribe((obj)=>{
      console.log(obj)
    });
  }
}
 

Add in tsconfig.json:

include in tsconfig.json

 
"include": ["./src", "node_modules/ngrxstoredata/store"]
 

License

MIT

Package Sidebar

Install

npm i ngrxstoredata

Weekly Downloads

6

Version

2.0.0

License

MIT

Unpacked Size

5.1 kB

Total Files

10

Last publish

Collaborators

  • vashramberani