barrel-rivers
v6.16.0
Published
RxJS based state management
Maintainers
Readme
RxJS based state management
This projects provides a basic toolset to manage states.
Example
Primitive type
const counterState = state(0);
const increment = () => counterState.set((currentCount) => ++currentCount);
const decrement = () => counterState.set((currentCount) => --currentCount);
counterState.value$.subscribe((count) => console.log(`Count is ${count}`));
increment();
counterState.set(8);
decrement();
// console output
// Count is 0
// Count is 1
// Count is 8
// Count is 7Object
const counterState = state({ count: 0, lastUpdated: new Date() });
const increment = () => {
counterState.set(
update(
(obj) => obj.count,
(count) => ++count
)
);
counterState.set(update((obj) => obj.lastUpdated, new Date()));
};
const decrement = () => counterState.set((obj) => ({ count: obj.count - 1, lastUpdated: new Date() }));