MatthewWid/better-sse

Remove deprecated session buffer modification methods

MatthewWid opened this issue · 0 comments

Once #42 is implemented, the ability to directly modify the internal session buffer with the .event, .data, .id, .retry, .comment, .dispatch and .flush methods will be moved into a separate EventBuffer class that Session will create and use internally.

As such, these methods and the ability to modify the internal session buffer at all will become redundant as you can instead just instantiate a new EventBuffer yourself and write its data directly to the socket.


For example, where before you would modify the session buffer yourself to write individual fields:

const session = await createSession(req, res);

session
  .event("my-event")
  .id("my-custom-id")
  .data("my data 1")
  .data("my data 2")
  .dispatch()
  .flush();

You can now create your own buffer instead:

const buffer = createEventBuffer();

buffer
  .event("my-event")
  .id("my-custom-id")
  .data("my data 1")
  .data("my data 2")
  .dispatch();

res.write(buffer.read());

(The above code is not necessarily what the final API will look like.)


This avoids the need to instantiate an entire Session instance for users who simply want an easy way to write spec-compliant SSE fields over the wire, as well as reducing the API surface size for users who follow the most common use-case of only using the helper methods (.push, .stream and .iterate).


The aforementioned methods on the Session class are now deprecated and will be removed in the future. Possibly in version 1.0.0.