ng-storeon
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

ng-storeon

Storeon logo by Anton Lovchikov

A tiny event-based Redux-like state manager Storeon for Angular.

Read more about Storeon article.


How to use

import createStore from 'storeon'

// Initial state, reducers and business logic are packed in independent modules
let increment = store => {
  // Initial state
  store.on('@init', () => ({ count: 0 }))
  // Reducers returns only changed part of the state
  store.on('inc', ({ count }) => ({ count: count + 1 }))
}

export const store = createStore([increment])

// your NgModule

import { NgStoreonModule } from 'ng-storeon';

@NgModule({
  imports: [NgStoreonModule], // NgStoreonModule
  ...
  providers: [{
    provide: 'STOREON',
    useValue: store  // your store
  }],
  ...
// your component

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');
  }
}

Package Sidebar

Install

npm i ng-storeon

Weekly Downloads

0

Version

0.0.1

License

MIT

Unpacked Size

37.4 kB

Total Files

24

Last publish

Collaborators

  • irustm