forked from mermaid-js/mermaid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Move liveReload code into script.
- Loading branch information
1 parent
fe1a062
commit 718d52a
Showing
4 changed files
with
34 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,3 +46,4 @@ stats/ | |
|
||
demos/dev/** | ||
!/demos/dev/example.html | ||
!/demos/dev/reload.js |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Connect to the server and reload the page if the server sends a reload message | ||
const connectToEvents = () => { | ||
const events = new EventSource('/events'); | ||
const loadTime = Date.now(); | ||
events.onmessage = (event) => { | ||
const time = JSON.parse(event.data); | ||
if (time && time > loadTime) { | ||
location.reload(); | ||
} | ||
}; | ||
events.onerror = (error) => { | ||
console.error(error); | ||
events.close(); | ||
// Try to reconnect after 1 second in case of errors | ||
setTimeout(connectToEvents, 1000); | ||
}; | ||
events.onopen = () => { | ||
console.log('Connected to live reload server'); | ||
}; | ||
}; | ||
|
||
setTimeout(connectToEvents, 500); |
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