-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
connect mercure endpoint url to noti controller directly
adjusted motification controller to take mercure endpoint url directly as controller values rather than templating the endpoint separately and then extracting them from dom nodes if the endpoint isn't provided then it will not attempt to connect to mercure, effectively disabling them also fix controller related js files according to eslint rules overall functionality should remain the same
- Loading branch information
Showing
3 changed files
with
42 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
export default function | ||
subscribe(topics, cb) { | ||
const mercureElem = document.getElementById("mercure-url"); | ||
if (mercureElem) { | ||
const url = new URL(mercureElem.textContent.trim()); | ||
export default function subscribe(endpoint, topics, cb) { | ||
if (!endpoint) { | ||
return null; | ||
} | ||
|
||
topics.forEach(topic => { | ||
url.searchParams.append('topic', topic); | ||
}) | ||
const url = new URL(endpoint); | ||
|
||
const eventSource = new EventSource(url); | ||
eventSource.onmessage = e => cb(e); | ||
topics.forEach((topic) => { | ||
url.searchParams.append('topic', topic); | ||
}); | ||
|
||
return eventSource; | ||
} | ||
return null; | ||
const eventSource = new EventSource(url); | ||
eventSource.onmessage = (e) => cb(e); | ||
|
||
return eventSource; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters