cubis
v0.0.6
Published
A state management that inspired on BLoC (Flutter)
Downloads
11
Readme
Cubis
A state management that inspired on BLoC (Flutter)
import { createDescriptor, createAction } from 'cubis';
// defining a cubis with initial state = 1
const counterCubis = createDescriptor(1);
// defining cusbis's actions
// a cubis action retrieves context object. changing context.state prop to make cubis's state update
const incrementAction = createAction((context) => context.state++);
const decrementAction = createAction((context) => context.state--);
// creating a cubis instance
const counter$ = counterCubis.create();
// getting current state of cubis
console.log(counter$.state); // 1
// dispatch an action
counter$.dispatch(incrementAction);
console.log(counter$.state); // 2
counter$.dispatch(decrementAction);
console.log(counter$.state); // 1