@fun-land/observable-fun-state
v2.0.0
Published
Use FunState with zen-observable!
Downloads
21
Readme
@fun-land/observable
Use FunState with zen-observable!
API
observableFunState
<State>(initialState: State) => Observable<FunState<State>>
Create an Observable of a FunState which calls Observable.next() when subscribers modify the state using the FunState API.
import observableFunState from "@fun-land/observable";
const observableState = observableFunState({ counter: 0 });
observableState.subscribe((funState) => {
// can read from funState like usual
const currentCount = funState.prop("counter").get();
console.log(currentCount);
if (currentCount < 10) {
// writing to the state causes another event
funState.prop("counter").mod((v) => v + 1);
}
}, 100);
});
Why?
This allows usage of FunState for doing reactive programming with accessors without requiring use-fun-state or React.js.