Skip to content
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 Request: Shorthand signature for emit #35

Closed
brianneisler opened this issue Jul 26, 2017 · 2 comments
Closed

Feature Request: Shorthand signature for emit #35

brianneisler opened this issue Jul 26, 2017 · 2 comments

Comments

@brianneisler
Copy link
Contributor

brianneisler commented Jul 26, 2017

The current spec outlines the emit function signature as the following

gateway.emit({
  event: "userCreated",
  data: JSON.stringify({ name: "Austen" }),
})

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'
})
@nikgraf
Copy link
Contributor

nikgraf commented Jul 31, 2017

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

@RafalWilinski
Copy link

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).

@nikgraf nikgraf closed this as completed Feb 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants