Refactor the whole asynchronous route action control flow using async/await syntax and make the go method return a Promise.
⚠️This will break how the current action control flow works with the state.resolve() and state.reject() methods.
This refactor should be released as the v3.
import highway from 'backbone-highway'
highway.route({
name: 'profile',
path: '/users/:name',
action: async (state) => {
console.log(`Hello ${state.params.name}`)
// Get some user data
const data = await fetch(`/api/users/${state.params.name}`)
return data.id // 42
}
})
const userId = await highway.go({ name: 'profile', params: { name: 'rascarlito' })
console.log('User id #', userId) // User id #42
I don't think actually getting data from calling the router should actually be very useful, but listening to when the route action has actually finished executing is.
Refactor the whole asynchronous route action control flow using
async/await
syntax and make thego
method return aPromise
.⚠️This will break how the current action control flow works with the
state.resolve()
andstate.reject()
methods.This refactor should be released as the v3.
I don't think actually getting data from calling the router should actually be very useful, but listening to when the route action has actually finished executing is.