funkia / turbine

Purely functional frontend framework for building web applications
MIT License
685 stars 27 forks source link

Modeview: Child could not be converted to component #121

Closed janat08 closed 4 years ago

janat08 commented 4 years ago

https://codesandbox.io/s/keen-merkle-bxkpx?file=/src/index.js

limemloh commented 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);
janat08 commented 4 years ago

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.

limemloh commented 4 years ago

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);
janat08 commented 4 years ago

Btw examples are also outdated, (don't run).