See this jsPerf test.
The most performant way to store data related to a certain element is to use a Map. Besides being the fastest, it also allows you to store arbitraty data. Using dataset and data-* attributes only allow for string values.
See this jsPerf test.
The most performant way to store data related to a certain element is to use a Map. Besides being the fastest, it also allows you to store arbitraty data. Using dataset and data-* attributes only allow for string values.
| class SampleApp() { | |
| constructor () { | |
| this.pageLoadingPromise = null; | |
| } | |
| waitForDomContentLoaded() { | |
| if (!this.pageLoadingPromise) { | |
| // this is the first time; prepare the promise | |
| this.pageLoadingPromise = new Promise(resolve => { |
| :root { | |
| --app-width: 1000px; | |
| --some-calculation: calc(var(--app-width) + 1); | |
| } |
Last updated: 2021-02-21, tested with socket.io v3.1.1
This is the simplest implementation you will find for a client/server WebSockets architecture using socket.io.
To see a full explanation, read my answer on SO here: https://stackoverflow.com/a/24232050/778272.
If you're looking for examples using frameworks, check these links:
| // will print numbers from 0 to 19 | |
| for (const x of range(20)) { | |
| console.info(x); | |
| } | |
| // will print | |
| // 0 0 | |
| // 1 0 | |
| // 0 1 | |
| // 1 1 |
| async function getJson(url) { | |
| return JSON.parse(await getFile(url)); | |
| } | |
| async function getFile(url) { | |
| return new Promise((resolve, reject) => { | |
| const request = new XMLHttpRequest(); | |
| request.addEventListener("load", function () { | |
| try { | |
| resolve(this.responseText); |
| /** | |
| * Asynchronously sleep for the specified amount of time. | |
| * @param {Number} millis | |
| * @return {Promise} | |
| */ | |
| function sleep(millis) { | |
| return new Promise(resolve => setTimeout(resolve, millis)); | |
| } |
Example .ssh/config file:
# severals rules that depend on the wildcard rule at the bottom
Host foo.com
HostName foo.com
User foo
IdentityFile /path/to/id-1