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
/* eslint-disable */ | |
let id = 0; | |
function retryAsync(fn) { | |
const guid = arguments[1] || {}; | |
return new Promise(resolve => { | |
resolve(fn(() => guid)); | |
}) | |
.then(value => value === guid ? |
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 displayImgEl = document.querySelector('main div img'); | |
// Bind an "onImgClick" function to all image elements found | |
const els = document.querySelectorAll('.thumb-bar img'); | |
els.forEach((el => el.addEventListener('click', onImgClick)); | |
function onImgClick(event) { | |
// Get the current element which was clicked. | |
// Could also use event.target too | |
const el = event.currentTarget; |
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
console.clear(); | |
var intervalIds = { | |
nextId: 1, | |
}; | |
/** | |
* Invoke a function callback on an interval delay. This is better than setInterval, as it... | |
* 1. Waits for the function to complete before starting the next interval | |
* 2. Waits for the optional returned Promise to resolve before starting the next interval |
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
// URL: https://github.com/wildpeaks/package-snapshot-dom/blob/master/src/snapshot.js | |
console.clear(); | |
function snapshotDOM(node, nodes, path) { | |
nodes = nodes || []; | |
if (!isObject(node)) { | |
return nodes; | |
} |
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
function evaluate(code, args = {}) { | |
// Call is used to define where "this" within the evaluated code should reference. | |
// eval does not accept the likes of eval.call(...) or eval.apply(...) and cannot | |
// be an arrow function | |
return function evaluateEval() { | |
// Create an args definition list e.g. "arg1 = this.arg1, arg2 = this.arg2" | |
const argsStr = Object.keys(args) | |
.map(key => `${key} = this.${key}`) | |
.join(','); | |
const argsDef = argsStr ? `let ${argsStr};` : ''; |
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
/** | |
* Resolve or reject a {@link Promise|Promise} based on the return value of a function. | |
* If a truthy value is returned, then the {@link Promise|Promise} is | |
* resolved with the truthy value; otherwise, if a falsy value, it's rejected with the reason | |
* defined as an instance of Error | |
* | |
* @memberof Promise | |
* @param {Function} fn Function to invoke and compare the return value of | |
* @param {*} [comparison] Optional comparison value to compare with the return value of the function; | |
* otherwise, default to truthy/falsy comparison |
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
// Both Subject and ReplaySubject | |
function Subject() { | |
if (!(this instanceof Subject)) { | |
throw new TypeError('"Subject" cannot be called as a function. Use the "new" keyword to construct a new "Subject" object'); | |
} | |
var _this = this; | |
['unsubscribe', 'next', 'error', 'complete'] |
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
function Feed(subscriber) { | |
if (!(this instanceof Feed)) { | |
throw new TypeError('"Feed" cannot be called as a function. Use the "new" keyword to construct a new "Feed" object'); | |
} | |
if (typeof subscriber !== 'function') { | |
throw new TypeError('Invalid argument, expected "subscriber" to be a function data type'); | |
} | |
this._subscriber = subscriber |
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
// Create an object for checking if an internal object error/value combination or a simple value | |
var _internal = { | |
name: 'Chainer' | |
}; | |
function Chainer(initial) { | |
var internal = _isInternal(initial) ? | |
initial : | |
_createInternal(null, initial); |
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
function Queue(iterable) { | |
if (!(this instanceof Queue)) { | |
throw new TypeError('"Queue" cannot be called as a function. Use the "new" keyword to construct a new "Queue" object'); | |
} | |
this._queue = []; | |
if (!_isArrayLike(iterable)) { | |
return; | |
} |