Skip to content

Instantly share code, notes, and snippets.

View SequentialPromise.js
clear();
var http = {
get(url) {
var delay = Math.floor( Math.random() * 10 ), even = !(delay % 2);
var xhr = new Promise(exe);
console.log(`REQUEST`, url, delay);
xhr.then( (data) => console.log(`SUCCESS: `, data) ).catch( (data) => console.log(`FAILURE: `, data) );
@cScarlson
cScarlson / sample.08-06-2020.ts
Created Jun 8, 2020
The [Reusable] Chain of Responsibility Pattern (TypeScript)
View sample.08-06-2020.ts
class Handler {
respond(e: CustomEvent): any {
return e.detail; // continue and provide same value (see Function Purity)
}
}
/**
* @name: The Chain of Responsibility Pattern
* @intention
@cScarlson
cScarlson / onany.js
Created Apr 8, 2020
Listen for any event on any target.
View onany.js
clear();
/**
* @param : source := EventTarget
* * EventTarget.prototype
* * Node (Element, Attr, etc)
* @usage : [Node].addEventListener('*', ({ detail: e }) => {...}, false);
*/
function proxyEventTargetSource(source) {
var emit = source.dispatchEvent; // obtain reference