All Projects → yamalight → Rxstate

yamalight / Rxstate

Simple opinionated state management library based on RxJS

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Rxstate

space-state
Demo app for Subjecting State to Good Behavior
Stars: ✭ 46 (+0%)
Mutual labels:  rxjs, state-management
rxdeep
rxjs deep state management
Stars: ✭ 47 (+2.17%)
Mutual labels:  rxjs, state-management
flow-state
UI state management with RxJS.
Stars: ✭ 33 (-28.26%)
Mutual labels:  rxjs, state-management
ng-effects
Reactivity system for Angular. https://ngfx.io
Stars: ✭ 46 (+0%)
Mutual labels:  rxjs, state-management
Fluorine
[UNMAINTAINED] Reactive state and side effect management for React using a single stream of actions
Stars: ✭ 287 (+523.91%)
Mutual labels:  rxjs, state-management
mst-effect
💫 Designed to be used with MobX-State-Tree to create asynchronous actions using RxJS.
Stars: ✭ 19 (-58.7%)
Mutual labels:  rxjs, state-management
juliette
Reactive State Management Powered by RxJS
Stars: ✭ 84 (+82.61%)
Mutual labels:  rxjs, state-management
Ayanami
🍭 A better way to react with state
Stars: ✭ 129 (+180.43%)
Mutual labels:  rxjs, state-management
Akita
🚀 State Management Tailored-Made for JS Applications
Stars: ✭ 3,338 (+7156.52%)
Mutual labels:  rxjs, state-management
reactive-store
A store implementation for state management with RxJS
Stars: ✭ 29 (-36.96%)
Mutual labels:  rxjs, state-management
vuse-rx
Vue 3 + rxjs = ❤
Stars: ✭ 52 (+13.04%)
Mutual labels:  rxjs, state-management
Platform
Reactive libraries for Angular
Stars: ✭ 7,020 (+15160.87%)
Mutual labels:  rxjs, state-management
Model
Angular Model - Simple state management with minimalist API, one way data flow, multiple model support and immutable data exposed as RxJS Observable.
Stars: ✭ 242 (+426.09%)
Mutual labels:  rxjs, state-management
ngx-mobx
Mobx decorators for Angular Applications
Stars: ✭ 14 (-69.57%)
Mutual labels:  rxjs, state-management
Reactive State
Redux-clone build with strict typing and RxJS down to its core. Wrist-friendly, no boilerplate or endless switch statements
Stars: ✭ 135 (+193.48%)
Mutual labels:  rxjs, state-management
aurelia-hoc-store
An Aurelia application showing the use of higher order components and a single state approach.
Stars: ✭ 20 (-56.52%)
Mutual labels:  rxjs, state-management
Store
Aurelia single state store based on RxJS
Stars: ✭ 103 (+123.91%)
Mutual labels:  rxjs, state-management
Bloc.js
A predictable state management library that helps implement the BLoC design pattern in JavaScript
Stars: ✭ 111 (+141.3%)
Mutual labels:  rxjs, state-management
ngx-model-hacker-news-example
Example repository with Hacker News implementation using Angular, Angular Material & ngx-model
Stars: ✭ 27 (-41.3%)
Mutual labels:  rxjs, state-management
Focal
Program user interfaces the FRP way.
Stars: ✭ 613 (+1232.61%)
Mutual labels:  rxjs, state-management

RxState

npm MIT Build Status Coverage Status

Simple opinionated state management library based on RxJS

Installation

npm install --save rxstate rxjs

Quick start

Example code for creating a store with status and typeahead fetching action is shown below:

import fetchival from 'fetchival';
import {from} from 'rxjs';
import {map, filter, debounceTime, distinctUntilChanged, tap, flatMap} from 'rxjs/operators';
import {createStore, createAction, createStatus} from 'rxstate';

// create status action
const status = createStatus();

// create action that fetches typeahead suggestions from server
const getTypeahead = createAction();
const typeahead$ = getTypeahead.$.pipe(
  map(e => e.target.value),
  filter(q => q.length > 3),
  debounceTime(300),
  distinctUntilChanged(),
  tap(() => status('loading')),
  flatMap(q => from(fetchival(typeaheadAPI).post({q}))),
  tap(() => status('done'))
);

// create an array of action streams for store
const streams = [status.$, typeahead$];
// create store
const store = createStore({streams, defaultState: {init: true}});

// other place in code:
// subscribe for state updates
store.subscribe(state => {
  console.log(state);
  // ... handle your state here
});

// other place in code:
// trigger action
getTypeahead('keyword');

Things to keep in mind

  • Rxstate has RxJS as peer dependency - don't forget to install it as well!
  • Store will always return last value to new subscribers.
  • By default, the state is updated using spread operator on new and old state (e.g. {...oldState, ...newState}). You can change that by passing combinator parameter during store creation, e.g.:
// create combinator that always returns new state
const combinator = (_, data) => data;
// create store
const store = createStore({streams, defaultState, combinator});
  • Status action and stream can be created using createStatus function. By default it'll write status as {status: 'statusText'}. Key can be changed by passing the string parameter to the function, e.g.:
// create status with custom key
const status = createStatus('customStatus');
// state will be updated with {customStatus: 'statusText'}
  • Stores have .clear() method that accepts new initial state as an optional argument and dispatches new action with either provided or default state as value. If you use default combinator logic - this will reset your state to initial one.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].