express-sse icon indicating copy to clipboard operation
express-sse copied to clipboard

Initial array - event types?

Open sp00x opened this issue 6 years ago • 4 comments

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.

sp00x avatar Mar 02 '18 15:03 sp00x

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

sp00x avatar Mar 02 '18 15:03 sp00x

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.

dpskvn avatar Mar 03 '18 14:03 dpskvn

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.

sp00x avatar Mar 05 '18 12:03 sp00x

Might as well throw in IDs into the mix here when this is implemented.

Bo98 avatar Nov 02 '19 22:11 Bo98