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

Refactor async route execution using async/await syntax #45

Open
ghost opened this issue Apr 7, 2018 · 1 comment
Open

Refactor async route execution using async/await syntax #45

ghost opened this issue Apr 7, 2018 · 1 comment

Comments

@ghost
Copy link

ghost commented Apr 7, 2018

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.

@ghost ghost added the enhancement label Apr 7, 2018
@ghost
Copy link
Author

ghost commented Apr 13, 2018

Maybe re-implement or pull in things from #31 (comment)

@ghost ghost mentioned this issue Apr 13, 2018
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

0 participants