-
Notifications
You must be signed in to change notification settings - Fork 352
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
feat(core): Improved control flow with times
and stopPropagation
#202
Conversation
@@ -201,6 +201,42 @@ describe('Integration | Server', function() { | |||
/Invalid filter callback provided/ | |||
); | |||
}); | |||
|
|||
it('.times()', async function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth adding a test for the precedence between times()
+ { times }
when both are used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -11,7 +13,9 @@ export default class Handler extends Map { | |||
super(); | |||
|
|||
this.set('config', {}); | |||
this.set('defaultOptions', {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious why the name defaultOptions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its more future proofing than anything else. Will allow us to add more API to modify default options passed to the interceptor/events.
Description
This PR includes 2 features that when used together, can be really powerful.
The first is the ability to remove an intercept or event handler after a specified amount of times it has been called via the handler's
.times(n)
API or by providing it as an option to.on(eventName, fn, { times })
or.intercept(fn, { times })
.The second, is the ability to prevent calling the next handlers registered for the events or intercept. This can be done via
interceptor.stopPropagation()
or via a new Event instance passed to every event handler by callingevent.stopPropagation()
.Motivation and Context
Lets take an example where we might want to intercept a user being removed. The first call to GET the user should return the user's info but after we delete the user, it should return a 404.
Then when the following requests get made, we are able to simulate the correct responses:
Types of Changes
Checklist