-
Notifications
You must be signed in to change notification settings - Fork 40
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: array subscriptions #657
feat: array subscriptions #657
Conversation
* | ||
* @param events array of events to subscribe to | ||
*/ | ||
export const OnEvents = ( |
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.
Instead of introducing a new decorator, could we just modify the @OnEvent
implementation to use the "extendArrayMetadata" under the hood?
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.
The original decorator already accepts string|string[], so introducing string[]|string[][] would not be backwards compatible (can't tell if the string array is an array of events, or a single event with array representing the namespaces)
The PR changes allow OnEvent to be used multiple times on the same method properly, just the new decorator was added to allow conflicting signatures without breaking backwards compat (OnEvent calls OnEvents internally with a single element array).
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.
I'm not saying that we should update the decorator signature, but just use the "extendArrayMetadata" function under the hood, as you did in the OnEvents
decorator
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.
Without OnEvents decorator it would still be impossible to attach events based on a dynamic array (say, based on a config class etc)
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.
That's fine, we don't want to support such a feature in this package
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.
Then I can remove this, but this would force users who need this use-case (incl me and commenters on the original issue[s]) to resort to monkey-patching decorator metadata with custom code instead of an easy to use decorator.
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.
If you want to dynamically retrieve event names (and dynamically register handlers for them), you shouldn't use decorators in the first place
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.
Example of dynamic parameters in decorators from nestjs docs https://docs.nestjs.com/fundamentals/custom-providers#class-providers-useclass
This will be impossible (say IS_DEV?['event1', 'event2']:['event1']
)
Removing OnEvents
from PR.
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.
This is a different use case than what's stated in the docs
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.
Removed
677b251
to
052fef4
Compare
looking forward to this being published 🚀 |
052fef4
to
65f5f49
Compare
Rebased to newest master. |
A nice feature - we spent some time figuring out why passing an array doesn't work |
I've made this fix in ~1h since first opening a github issue. I hope everything is alright with @kamilmysliwiec - assuming so, since still active on gh. In the meantime, my fork can be used by adding
to the fork includes a "multi event" decorator, which is optional. Might publish npm package of the fork later, if longer term solution is required |
LGTM |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #654
What is the new behavior?
@OnEvents
Does this PR introduce a breaking change?
Other information