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
This verbose signature is good as there are additional properties we may want to add like the meta property etc as the gateway matures. serverless/event-gateway#179
However, it may be nice to offer a shorthand signature in some cases where all you're doing is sending events with some simple data payload.
gateway.emit('some.event.type',{'i': 'am data'})
The text was updated successfully, but these errors were encountered:
I suggest we aim for an API where there is one way of doing the same thing. Multiple ways just make it harder to document and lead to more confusion for newcomers and makes it harder for users to parse others people code of they use the other style.
Should we change emit to the proposed signature?
Personally I believe the initial version is better because:
having one argument is more extensible for the future
having one argument makes it easier for functional programming in JS since currying is not needed
being explicit about the key event helps to parse the code
For me, signature proposed by @brianneisler seems more natural for two reasons:
There's a clear separation of event name/type which basically routes the event and the "payload"
It's very similar to sending a POST request in axios, fetch, or many other libraries performing similar things. I think this might make things more intuitive for new developers.
Regarding one argument being more extensible: second parameter of the function could be an object containing data, meta and all other things (just like axios/fetch).
The current spec outlines the emit function signature as the following
This verbose signature is good as there are additional properties we may want to add like the
meta
property etc as the gateway matures. serverless/event-gateway#179However, it may be nice to offer a shorthand signature in some cases where all you're doing is sending events with some simple data payload.
The text was updated successfully, but these errors were encountered: