dangvanthanh / hyperapp-rollup

Hyperapp Rollup Boilerplate
3 stars 0 forks source link

'async' problem #1

Open algebraic-brain opened 6 years ago

algebraic-brain commented 6 years ago

Thanks a lot for this boilerplate.

I used it with simplest hyperapp code:

import { h, app } from "hyperapp"

const state = {
  count: 0
}

const actions = {
  down: () => state => ({ count: state.count - 1 }),
  up: () => state => ({ count: state.count + 1 })
}

const view = (state, actions) => (
  <main>
    <h1>{state.count}</h1>
    <button onclick={actions.down}>-</button>
    <button onclick={actions.up}>+</button>
  </main>
)

const main = app(state, actions, view, document.body)

And everything works just fine.

But I need this to be made async in order to add await calls inside:

import { h, app } from "hyperapp"

async function appEntry() {

  const state = {
    count: 0
  }

  const actions = {
    down: () => state => ({ count: state.count - 1 }),
    up: () => state => ({ count: state.count + 1 })
  }

  const view = (state, actions) => (
    <main>
      <h1>{state.count}</h1>
      <button onclick={actions.down}>-</button>
      <button onclick={actions.up}>+</button>
    </main>
  )

  window.main = app(state, actions, view, document.body)
}

appEntry();

and now I have the following problem:

[!] (uglify plugin) Error: Error transforming bundle with 'uglify' plugin: Unexpected token: keyword (function)

This error disappears when I remove async keyword. What I do wrong? Please help.

dangvanthanh commented 6 years ago

Thank you @algebraic-brain

Now hyperapp-rollup support async.