bs-effector-react
ReasonML bindings for effector-react.
Installation
npm install --save bs-effector-react
Then add bs-effector to bs-dependencies in your bsconfig.json
:
{
"bs-dependencies": ["bs-effector-react"]
}
Usage
open Effector;
let counter = Store.make(0);
let increment: Event.t(unit) = Event.make("increment");
counter
|> Store.watch(state => Js.log(state));
counter
|> Store.on(increment, (state, _) => state + 1);
let component = EffectorReact.createComponent(counter);
let make = (_children) => {
...component,
render: self =>
<div className="counter">
(ReasonReact.stringToElement("counter: " ++ string_of_int(self.state)))
<br />
<button onClick=(_ => increment())>
(ReasonReact.stringToElement("increment"))
</button>
</div>,
};
0.18.2
-
Fix webpack usage issue. To prevent this in a future, webpack integration test was added.
-
Improve typescript typings for createApi
. This code example became type checked
import {createStore, createApi} from 'effector'
const $text = createStore('')
const {addMessage, cut} = createApi($text, {
addMessage: (text, message) => text + `\n` + message
cut: (text, {fromIndex, size}) => text.slice(fromIndex, fromIndex + size),
})
- Add umd bundle to npm. Therefore, you can use cdn to include library without bundlers
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/effector@0.18.2/effector.umd.js"></script>
</head>
<body>
<script>
const header = document.createElement('h1')
document.body.appendChild(header)
const $text = effector.createStore('hello')
$text.watch(str => (header.innerHTML = str))
</script>
</body>
</html>