Hoodie client needs to do some asynchronous cross-module initialisation, see https://github.com/hoodiehq/hoodie-client/issues/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
})
})
})
📋 part of https://github.com/hoodiehq/camp/issues/101
Hoodie client needs to do some asynchronous cross-module initialisation, see https://github.com/hoodiehq/hoodie-client/issues/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:
Based on the discussion at https://github.com/hoodiehq/hoodie-client/issues/42 I created before-after-hook with which we can change the above to