Skip to content

[DX] Longer variable names in Mercure documentation #12252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions mercure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ Subscribing to updates in JavaScript is straightforward:

.. code-block:: javascript

const es = new EventSource('http://localhost:3000/hub?topic=' + encodeURIComponent('http://example.com/books/1'));
es.onmessage = e => {
const eventSource = new EventSource('http://localhost:3000/hub?topic=' + encodeURIComponent('http://example.com/books/1'));
eventSource.onmessage = event => {
// Will be called every time an update is published by the server
console.log(JSON.parse(e.data));
console.log(JSON.parse(event.data));
}

Mercure also allows to subscribe to several topics,
Expand All @@ -201,16 +201,16 @@ and to use URI Templates as patterns:
.. code-block:: javascript

// URL is a built-in JavaScript class to manipulate URLs
const u = new URL('http://localhost:3000/hub');
u.searchParams.append('topic', 'http://example.com/books/1');
const url = new URL('http://localhost:3000/hub');
url.searchParams.append('topic', 'http://example.com/books/1');
// Subscribe to updates of several Book resources
u.searchParams.append('topic', 'http://example.com/books/2');
url.searchParams.append('topic', 'http://example.com/books/2');
// All Review resources will match this pattern
u.searchParams.append('topic', 'http://example.com/reviews/{id}');
url.searchParams.append('topic', 'http://example.com/reviews/{id}');

const es = new EventSource(u);
es.onmessage = e => {
console.log(JSON.parse(e.data));
const eventSource = new EventSource(url);
eventSource.onmessage = event => {
console.log(JSON.parse(event.data));
}

.. tip::
Expand Down Expand Up @@ -317,12 +317,12 @@ and to subscribe to it:
const hubUrl = response.headers.get('Link').match(/<([^>]+)>;\s+rel=(?:mercure|"[^"]*mercure[^"]*")/)[1];

// Append the topic(s) to subscribe as query parameter
const h = new URL(hubUrl);
h.searchParams.append('topic', 'http://example.com/books/{id}');
const hub = new URL(hubUrl);
hub.searchParams.append('topic', 'http://example.com/books/{id}');

// Subscribe to updates
const es = new EventSource(h);
es.onmessage = e => console.log(e.data);
const eventSource = new EventSource(hub);
eventSource.onmessage = event => console.log(event.data);
});

Authorization
Expand Down