Skip to content

Commit

Permalink
Updating the README, adding more details
Browse files Browse the repository at this point in the history
  • Loading branch information
lolo32 committed Sep 5, 2017
1 parent 2d7816f commit 1e314d7
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,33 @@ You could specify:
It must be a function that will be called with the event in parameter, and must return a string that will be the
`id` of the SSE, or it could be `null` if no id is needed.

Using a function:

```javascript
reply.sse("message", {
idGenerator(event) {
idGenerator: (event) => {
// Retrieve the event name using the key myIdentifiant or use the timestamp if not exists …
return event.myIdentifiant || (new Date()).getTime();
}
});
```

It will transmit:

> id: 1504624133267
>
> data: message
Do not display `id`, so pass null:

```javascript
reply.sse("message", {idGenerator: null});
```

It will transmit:

> data: message
### event

It could be:
Expand All @@ -107,8 +126,8 @@ name doest not change. The event will be retrieved by the browser using `.on("ev
`.on("message", […])`.

```javascript
reply.sse("message", {
event(event) {
reply.sse({myEventName: "myEvent", hello: "world"}, {
event: (event) => {
// Retrieve the event name using the key myEventName …
const name = event.myEventName;
// … delete it from the object …
Expand All @@ -118,3 +137,11 @@ reply.sse("message", {
}
});
```

It will transmit:

> id: 1
>
> event: MyEvent
>
> data: {"hello":"world"}

0 comments on commit 1e314d7

Please sign in to comment.