You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(onBefore): Run onBefore hooks asynchronously.
BREAKING CHANGE: `onBefore` hooks are now run asynchronously like all the other hooks.
- #### Old behavior
Previously, the `onBefore` hooks were run in the same stackframe as `transitionTo`.
If they threw an error, it could be caught using try/catch.
```js
transitionService.onBefore({ to: 'foo' }), () => { throw new Error('doh'); });
try {
stateService.go('foo');
} catch (error) {
// handle error
}
```
- #### New behavior
Now, `onBefore` hooks are processed asynchronously.
To handle errors, use any of the async error handling paradigms:
- Chain off the promise
```js
transitionService.onBefore({ to: 'foo' }), () => { throw new Error('doh'); });
stateService.go('foo').catch(error => { //handle error });
```
- Define an error handler
```js
transitionService.onBefore({ to: 'foo' }), () => { throw new Error('doh'); });
transitionService.onError({ to: 'foo' }), () => { // handle error });
stateService.go('foo');
```
- Use the global defaultErrorHandler
```js
transitionService.onBefore({ to: 'foo' }), () => { throw new Error('doh'); });
stateService.go('foo');
stateService.defaultErrorHandler(error => { // global error handler });
```
- #### Motivation
Why introduce a BC?
- No subtle behavior differences by hook type
- Simpler code and mental model
- Fewer edge cases to account for
- #### BC Liklihood
How likely is this to affect my app?
Very Low: Apps that registered onBefore hooks and depend on
synchronous execution are affected.
- #### BC Severity
How severe is this BC?
Low: Switch to asynchronous handling, such as chaining off the
transition promise
0 commit comments