azu / predable

Predable is state management framework without framework code.
MIT License
7 stars 0 forks source link

How to know state changes? #1

Open azu opened 4 years ago

azu commented 4 years ago

Missing onChange

azu commented 4 years ago
import { shallowEqual } from "shallow-equal-object";
const onChange = (cb) => {
  const detectChanges = () => {
    if(!shallowEqual(currentState, getState()){
      cb();
    }
  }
};
azu commented 4 years ago

Maybe, onchange needs is related with specific framework. It will adaptor for XXX framework.

azu commented 4 years ago

https://github.com/facebookexperimental/Recoil/blob/c38012d92a292a4a867163cf7b14cfb3debddf01/src/components/Recoil_RecoilRoot.react.js#L74-L121 recoil implementations

azu commented 4 years ago

naive implemtation of onchage https://github.com/azu/predable/blob/2030f86c2db72347c84940d11a9e00830866b38e/examples/counter/src/CounterState.ts#L11-L18