The power of streams, now in ReasonReact!
npm install reason-react-waffleReasonReactWaffle provides React HOC (Higher Order Component) to provide components an access to a Waffle.re stream, it updates the consumers whenever a value is poured into the stream. It helps with implementing Meiosis for state management.
ReasonReactWaffle is Experimental.
``reason
let str = ReasonReact.string;
module Counter = {
type state = {count:int};
type update = Inc | Dec;
let defaultState = {count: 0};
let updates = Waffle.scan((state, update) => switch (update){
| Inc => {count: state.count+1}
| Dec => {count: state.count-1}
},defaultState);
module C = {
type sInput = update;
type sOutput = state;
let name = "counter";
let stream = updates;
};
include ReasonReactWaffle.CreateConsumer(C);
};
let root = {
ReactDOMRe.renderToElementWithId(root, "target");
`
`sh`
npm install --save reason-react-waffle
Then add reason-react-waffle to bs-dependencies in your bsconfig.json:
`js``
{
...
"bs-dependencies": ["reason-react-waffle"]
}