A store implementation for state management with RxJS
https://yarn.pm/@lacolaco/reactive-store
$ npm i rxjs @lacolaco/reactive-store
- RxJS-based: Use the ecosystem
- TypeScript: Type-safe state management
- Simple: Easy to understand what the library does and doesn't
- Extensible: Easy to use your middlewares
- Angular: @lacolaco/ngx-store (v4.0.0+)
import { Store } from '@lacolaco/reactive-store';
const store = new Store('initialState');
assert.ok(store.getValue() === 'initialState');
store.patch(state => 'updated!');
assert.ok(store.getValue() === 'updated!');
import { Store } from '@lacolaco/reactive-store';
const store = new Store('initialState');
store.subscribe(state => {
console.log(state);
});
store.patch(state => 'updated!');
import { Store } from '@lacolaco/reactive-store';
const store = new Store({ count: 0 });
const count$ = store.select(state => state.count);
count$.subscribe(count => {
console.log(count);
});
store.patch(state => {
return {
count: state.count + 1,
};
});
import { Store, StateHandler, Middleware } from '@lacolaco/reactive-store';
const loggingMiddleware: Middleware = (next: StateHandler): StateHandler => {
return (state: any) => {
const newState = next(state);
console.log(`[State]`, newState);
return newState;
};
};
const store = new Store(0, [loggingMiddleware]);