nanobus
nanobus copied to clipboard
"Are the emitters asynchronous?"
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.
Events are async, but the logger in choo-devtools
isn't because we can't get timing information synchronously. Hope that makes sense!
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.
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