8000 [DX] Longer variable names in Mercure documentation · symfony/symfony-docs@31f5fb6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 31f5fb6

Browse files
stephanvierkantjaviereguiluz
authored andcommitted
[DX] Longer variable names in Mercure documentation
1 parent ee237fc commit 31f5fb6

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

mercure.rst

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ Subscribing to updates in JavaScript is straightforward:
189189

190190
.. code-block:: javascript
191191
192-
const es = new EventSource('http://localhost:3000/hub?topic=' + encodeURIComponent('http://example.com/books/1'));
193-
es.onmessage = e => {
192+
const eventSource = new EventSource('http://localhost:3000/hub?topic=' + encodeURIComponent('http://example.com/books/1'));
193+
eventSource.onmessage = event => {
194194
// Will be called every time an update is published by the server
195-
console.log(JSON.parse(e.data));
195+
console.log(JSON.parse(event.data));
196196
}
197197
198198
Mercure also allows to subscribe to several topics,
@@ -201,16 +201,16 @@ and to use URI Templates as patterns:
201201
.. code-block:: javascript
202202
203203
// URL is a built-in JavaScript class to manipulate URLs
204-
const u = new URL('http://localhost:3000/hub');
205-
u.searchParams.append('topic', 'http://example.com/books/1');
204+
const url = new URL('http://localhost:3000/hub');
205+
url.searchParams.append('topic', 'http://example.com/books/1');
206206
// Subscribe to updates of several Book resources
207-
u.searchParams.append('topic', 'http://example.com/books/2');
207+
url.searchParams.append('topic', 'http://example.com/books/2');
208208
// All Review resources will match this pattern
209-
u.searchParams.append('topic', 'http://example.com/reviews/{id}');
209+
url.searchParams.append('topic', 'http://example.com/reviews/{id}');
210210
211-
const es = new EventSource(u);
212-
es.onmessage = e => {
213-
console.log(JSON.parse(e.data));
211+
const eventSource = new EventSource(url);
212+
eventSource.onmessage = event => {
213+
console.log(JSON.parse(event.data));
214214
}
215215
216216
.. tip::
@@ -317,12 +317,12 @@ and to subscribe to it:
317317
const hubUrl = response.headers.get('Link').match(/<([^>]+)>;\s+rel=(?:mercure|"[^"]*mercure[^"]*")/)[1];
318318
319319
// Append the topic(s) to subscribe as query parameter
320-
const h = new URL(hubUrl);
321-
h.searchParams.append('topic', 'http://example.com/books/{id}');
320+
const hub = new URL(hubUrl);
321+
hub.searchParams.append('topic', 'http://example.com/books/{id}');
322322
323323
// Subscribe to updates
324-
const es = new EventSource(h);
325-
es.onmessage = e => console.log(e.data);
324+
const eventSource = new EventSource(hub);
325+
eventSource.onmessage = event => console.log(event.data);
326326
});
327327
328328
Authorization

0 commit comments

Comments
 (0)
0