Last active
June 27, 2019 01:41
-
-
Save monjer/e5eb366d3bacaf73f2ae9553c5b682bb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const schedule = (() => { | |
| const taskQueue = []; | |
| const runTask = () => { | |
| while (taskQueue.length > 0) { | |
| const task = taskQueue.shift(); | |
| task(); | |
| } | |
| }; | |
| const isArray = (obj) => { | |
| return Object.prototype.toString.call(obj) === "[object Array]"; | |
| }; | |
| const node = document.createTextNode(""); | |
| const observer = new MutationObserver(() => { | |
| runTask(); | |
| }); | |
| observer.observe(node, { characterData: true }); | |
| return { | |
| push(tasks) { | |
| tasks = isArray(tasks) ? tasks : [tasks]; | |
| taskQueue.push(...tasks); | |
| node.textContent = node.textContent === "0" ? "1" : "0"; | |
| }, | |
| }; | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.