ng-storeon
A tiny event-based Redux-like state manager Storeon for Angular.
Read more about Storeon article.
How to use
import createStore from 'storeon'
let increment = store => {
store.on('@init', () => ({ count: 0 }))
store.on('inc', ({ count }) => ({ count: count + 1 }))
}
export const store = createStore([increment])
import { NgStoreonModule } from 'ng-storeon';
@NgModule({
imports: [NgStoreonModule],
...
providers: [{
provide: 'STOREON',
useValue: store
}],
...
import { Component, OnInit } from '@angular/core';
import { NgStoreonService } from 'ng-storeon';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
changes: any;
dispath: any;
constructor(private ngstoreon: NgStoreonService) { }
title = 'sroreon-angular';
ngOnInit() {
const { dispatch, changes } = this.ngstoreon.useStoreon('count');
this.dispath = dispatch;
this.changes = changes;
}
updateState() {
this.dispath('inc');
}
}