Closed janat08 closed 4 years ago
The example is a bit outdated, the output
method is renamed to use
, and we recommend using component
, instead of modelView
, since it has less boilerplate.
I'll make sure to update the documentation
Here is a more up-to-date example: https://codesandbox.io/s/vigorous-wood-qxv90?fontsize=14&hidenavigation=1&theme=dark
import { accum, combine } from "@funkia/hareactive";
import { runComponent, elements as E, component } from "@funkia/turbine";
const counter = component((on, start) => {
const increment = on.incrementClick.mapTo(1);
const decrement = on.decrementClick.mapTo(-1);
const changes = combine(increment, decrement);
const count = start(accum((n, m) => n + m, 0, changes));
return [
"Counter ",
count,
" ",
E.button("+").use({ incrementClick: "click" }),
" ",
E.button("-").use({ decrementClick: "click" })
];
});
runComponent("#mount", counter);
But with the component is there no way to test the model. I never write tests, but when I do, they involve chrome and selectors. I suppose that modelview is still an option.
yes, modelView
is still an option, the example would then be
import { accum, combine, instant } from "@funkia/hareactive";
import { runComponent, elements as E, modelView } from "@funkia/turbine";
const counterView = ({ count }) =>
E.div([
"Counter ",
count,
" ",
E.button("+").use({ incrementClick: "click" }),
" ",
E.button("-").use({ decrementClick: "click" })
]);
const counterModel = ({ incrementClick, decrementClick }) =>
instant(start => {
const increment = incrementClick.mapTo(1);
const decrement = decrementClick.mapTo(-1);
const changes = combine(increment, decrement);
const count = start(accum((n, m) => n + m, 0, changes));
return { count };
});
const counter = modelView(counterModel, counterView)();
runComponent("#mount", counter);
Btw examples are also outdated, (don't run).
https://codesandbox.io/s/keen-merkle-bxkpx?file=/src/index.js