nanobus icon indicating copy to clipboard operation
nanobus copied to clipboard

"Are the emitters asynchronous?"

Open timsim00 opened this issue 6 years ago • 3 comments

No. If you're interested in doing that, use something like nanotick to batch events and ensure they run asynchronously.

I'm probably misunderstanding something here, but I have a timing issue that sure seems async when calling emitter.emit.

module.exports = function view (state, emit, props = {}) {
  var id = state.params.msgId
  // emit('autopilot:edit-message', id)
  let {item} = state.autopilot.findItemById(id)
  state.autopilot.current = item

The listener for 'edit-message' only has the two lines that follow //emit... Calling emit instead of the two lines results in an error downstream because state.autopilot.current isn't set yet.

timsim00 avatar Mar 13 '18 13:03 timsim00

Events are async, but the logger in choo-devtools isn't because we can't get timing information synchronously. Hope that makes sense!

yoshuawuyts avatar Mar 13 '18 16:03 yoshuawuyts

I think it's because I'm loading this view by refreshing the page. App load behavior seems to be a bit different than just swapping out a view. Logs say there's no listener but it's still running the listener...three times, in fact. Maybe my app structure isn't setup quite right for this scenario.

timsim00 avatar Mar 14 '18 15:03 timsim00

Bit of a hack but this worked:

app store:

  emitter.on('DOMContentLoaded', function () {
    state.app.DOMContentLoaded = true

view

if (state.app.DOMContentLoaded) {
    do everything as normal
} else {
  return html``
}

I'm not sure why the view is rendering before DOMContentLoaded. Only have to do this on pages where the query param affects what's being displayed ..the route is .../something/:id

timsim00 avatar Mar 22 '18 21:03 timsim00