-
Notifications
You must be signed in to change notification settings - Fork 2
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
[FEATURE] New @OnEvent()
decorator
#17
Comments
OnEvent()
decorator
OnEvent()
decorator@OnEvent()
decorator
Hi Thomas, Great new feature, I am currently on vacation till 15th of January, after my return I will start working on this new decorator. Happy new year, |
No worries, Daniel. |
Hi Thomas, https://github.com/dxfrontier/cds-ts-dispatcher/tree/v0.1.20?tab=readme-ov-file#onevent - docu |
Thank you @dragolea |
@dragolea on related note: would it be possible to use |
I remember I tried to implement it at the beginning of this project but I was not able to find an overload for the Below we see all the overloads of the on<T extends Constructable>(eve: types.event, entity: T, handler: CRUDEventHandler.On<InstanceType<T>, InstanceType<T> | void | Error>): this
on<F extends CdsFunction>(boundAction: F, service: string, handler: ActionEventHandler<F['__parameters'], void | Error | F['__returns']>): this
on<F extends CdsFunction>(unboundAction: F, handler: ActionEventHandler<F['__parameters'], void | Error | F['__returns']>): this
on(eve: types.event, entity: types.target, handler: OnEventHandler): this
on(eve: types.event, handler: OnEventHandler): this I remember I've tried to see if the last overload is working but something didn't. ( on(eve: types.event, handler: OnEventHandler): this) I think you're referring to this error handler https://cap.cloud.sap/docs/node.js/core-services#srv-on-error Were you able to find the overload in TS for this error handler? |
It's coming soon to TS. The new types were just merged last week: cap-js/cds-types#9 |
@hakimio feel free to create a new issue for |
Description
Let's say you are emitting custom event with
srv.emit('OrderedBook', someData)
and you'd like to add a handler for this event. Right now you have to subscribe to the event manually by writing code like the following:It would be nice if there was a decorator like
@OnEvent('OrderedBook')
which would reduce the amount of boilerplate code you need to write to subscribe to custom events.Suggested solution
The text was updated successfully, but these errors were encountered: