2.0.0 • Published 9 months ago

@fun-land/observable-fun-state v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

@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.

2.0.0

9 months ago

1.1.10

3 years ago

1.1.13

3 years ago

1.1.9

3 years ago

1.1.7

3 years ago

1.1.3

3 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago