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 $ = (q, container = document) => [...container.querySelectorAll(q)]; | |
| $.createFragment = Range.prototype.createContextualFragment.bind( | |
| document.createRange() | |
| ); | |
| $.attr = (el, attrs) => { | |
| for (let prop in attrs) { | |
| HTMLElement.prototype.hasOwnProperty(prop) | |
| ? (el[prop] = attrs[prop]) |
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 randomBetween = (min, max) => | |
| Math.floor(Math.random() * (max - min + 1) + min) |
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 createEventBus = () => { | |
| const subscribers = {} | |
| let counter = 0 | |
| const on = (name, cb) => { | |
| if (!subscribers[name]) subscribers[name] = {} | |
| subscribers[name][++counter] = cb | |
| return btoa(name + '.' + counter) | |
| } |
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 onLocationChange = (() => { | |
| const subscribers = [] | |
| const fireEvent = () => subscribers.forEach(sub => sub()) | |
| const { pushState, replaceState } = window.history | |
| window.history.pushState = function(...args) { | |
| pushState.apply(window.history, args) | |
| fireEvent() | |
| } |
NewerOlder