Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Are the emitters asynchronous?" #26

Open
timsim00 opened this issue Mar 13, 2018 · 3 comments
Open

"Are the emitters asynchronous?" #26

timsim00 opened this issue Mar 13, 2018 · 3 comments

Comments

@timsim00
Copy link

timsim00 commented Mar 13, 2018

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.

@yoshuawuyts
Copy link
Member

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

@timsim00
Copy link
Author

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants