question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Emitter Should Optionally Be Static

See original GitHub issue

Describe the Bug

The HTTP Emitter should have static methods such that we don’t need to construct multiple Emitters before sending our CE.

Currently we must instantiate the Emitter with a URL and then emit. See README.

const { CloudEvent, Emitter } = require("cloudevents");

const ce = new CloudEvent({ type, source, data });
async function test() {
  const emitter = new Emitter({
    url: "https://cloudevents.io/example"
  });
  await emitter.send(ce);
}

Expected Behavior

Like the static Receiver.accept(...), I’d imagine an Emitter.send(...).

const { CloudEvent, Emitter } = require("cloudevents");

const ce = new CloudEvent({ type, source, data });
async function test() {
  await Emitter.send(ce, "https://cloudevents.io/example");
}

This format is more idiomatic and is similar to the format for what other npm modules do:

  • http Standard library – (http.request(url, options))
  • axios - (axios.post(url, options))
  • request - (request.post({ url, ...options }))
  • superagent - (superagent.post(url).send(body).end((err, res) => {}))

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:30 (30 by maintainers)

github_iconTop GitHub Comments

1reaction
lholmquistcommented, Aug 12, 2020

@grant i would suggest to send a PR with the proposed changes. Maybe seeing the code in context might help

1reaction
matejvasekcommented, Aug 11, 2020

I think that instance of Emitter is supposed to be used only locally in single file (or even function) and not being exported.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Embed With Elliot: The Static Keyword You Don't ... - Hackaday
Use the static keyword for variables within a function when you want the value to persist across function calls, but you don't need...
Read more >
compose-emitter - npm
Fast, lightweight and powerful composition of an EventEmitter with context binding in mind. Pass your emitter instance and context through ...
Read more >
Java static code analysis - SonarSource Rules
Public constants and fields initialized at declaration should be "static final" rather than merely "final" ... "Optional" should not be used for parameters....
Read more >
decode.generic package
Concatenate multiple emittersets into one emitterset which is returned. Optionally modify the frame indices by the arguments. Parameters. emittersets ( Iterable ) ...
Read more >
ShapeSpawnBehavior | @pixi/particle-emitter - PixiJS
A Spawn behavior that places (and optionally rotates) particles according to a specified ... Additional shapes must implement the SpawnShape interface, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found