DEV Community

artydev
artydev

Posted on • Updated on

Mithril, an unusual use ...

In this sample, just for experiment, i have include in the mix :

  • streams
  • jsx
  • pure functional component
/* @jsx m */
const stream  = window.m.stream

const started = stream(false)
started.map(x => x && m.redraw())

async function sleep(ms) {
   await new Promise(function(resolve) {
    setTimeout(resolve, ms)
  })
}

async  function fetchApi () {
  await sleep(2000)
  started(true)
}

function Comp () {
  return (
    <div oninit = {fetchApi}> {
      started() ? <h2>App started</h2> : <h4>waiting..</h4> }
    </div>
  )
}

m.mount(document.body, { view : Comp })
Enter fullscreen mode Exit fullscreen mode

You can test it here : MithrilExp

Top comments (0)