Emitter Should Optionally Be Static
See original GitHub issueDescribe 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:
- Created 3 years ago
- Comments:30 (30 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@grant i would suggest to send a PR with the proposed changes. Maybe seeing the code in context might help
I think that instance of Emitter is supposed to be used only locally in single file (or even function) and not being exported.