express-sse
express-sse copied to clipboard
Initial array - event types?
I haven't dug through the code yet, but I can't seem to decode by the docs if it is possible to set event types (or IDs) for the initial content ..?
e.g. I want to do [ { event: 'foo', data: { hello: 'world' } } ] to send a 'foo' event as initial content.
Derp. I see now there is a { initialEvent: 'single type' }
It would be good though if there was a way of specifying different types of events for the initial array..
That might be a nice thing to have, but if I was to implement it, I'd like to do it without breaking backwards compatibility.
I'll leave it as a consideration for future updates.
Yes, I realize that it is just a plain array of objects now, and adding any extra fields or stuff would break it.
Here's a quick idea for a solution:
What if you in the options did { initialEventProperty: '$type' }
and then if that is set, you would read the event type from the named property of the objects instead? If it isn't set, you're falling back to the existing functionality, ie either just event-less messages or using the value defined by options.initialEvent
e.g. [ { $type: "handshake", "hello": "world" }, { "foo": "bar" }, { $type: "something", "boo": "far" } ]
Then you'd have handshake, (default), something.
Might as well throw in IDs into the mix here when this is implemented.