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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace undocumented pre:{signin,signout} and post:{signin,signout} events with a hook API for signin and signout #124

Open
gr2m opened this issue Dec 10, 2016 · 0 comments

Comments

@gr2m
Copy link
Member

gr2m commented Dec 10, 2016

馃搵 part of hoodiehq/camp#101


Hoodie client needs to do some asynchronous cross-module initialisation, see hoodiehq/hoodie-client#3. Tradition events did not work for us as we for example need to be able to intercept a signout if the user has local changes and sync did fail.

For a lack of better alternatives, we introduced hidden events that pass options.hooks that can be used to add promises which have to be resolved before the actual method gets executed.

Example:

hoodie.account.on('pre:signout', function (options) {
  options.hooks.push(function () {
    return hoodie.store.push().catch(function (error) {
      if (error.status !== 401) { throw error }

      error.message = 'Local changes could not be synced, sign in first'
      throw error
    })
  })
})

Based on the discussion at hoodiehq/hoodie-client#42 I created before-after-hook with which we can change the above to

hoodie.account.hook.before('signout', function (options) {
  return hoodie.store.push().catch(function (error) {
    if (error.status !== 401) { throw error }

    error.message = 'Local changes could not be synced, sign in first'
    throw error
  })
})
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

1 participant