This file contains 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
// Iterating on the UMD template from here: | |
// https://github.com/umdjs/umd/blob/master/templates/returnExportsGlobal.js | |
// But experimentally improving it so that it works for webpack 2 | |
// UMD template from https://gist.github.com/Offirmo/ec5c7ec9c44377c202f9f8abcacf1061#file-umd-js | |
(function (root, factory) { | |
var LIB_NAME = 'Foo' | |
if (typeof define === 'function' && define.amd) { |
This file contains 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
https://github.com/terkelg/facon | |
// in Offirmo monorepo! | |
function poll(predicate, options) { | |
// early check to save an initial poll period | |
let result = predicate(); | |
if (result) | |
return Promise.resolve(result); |
This file contains 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
// debg | |
let DEBUG = false | |
try { // defensive! | |
DEBUG = DEBUG || !!window.localStorage.getItem(`${APP}.debug`) | |
} catch (e) { /* swallow */ } | |
if (DEBUG) console.info(`Hello from ${APP}`) | |
// prepare an url | |
// https://devdocs.io/javascript/global_objects/encodeuri |
This file contains 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
var global_module_instance; | |
Object.defineProperty(window, 'global_ng_module', { | |
enumerable: true, // why not ? | |
set: function() { | |
throw new Error('You can’t assign window.global_module !'); | |
}, | |
get: function() { | |
if(global_module_instance) return global_module_instance; // already OK | |
global_module_instance = angular.module('global_ng_module', [ | |
'ui.bootstrap' |
This file contains 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
// imports | |
import { Random, Engine } from '@offirmo/random' | |
import { | |
State as MetaState, | |
factory as meta_state_factory, | |
} from '@oh-my-rpg/state-meta' | |
// http://www.benmvp.com/learning-es6-enhanced-object-literals/ | |
return { |
This file contains 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
/////// fetch /////// | |
const originalFetch = window.fetch; | |
window.fetch = async (...args) => { | |
const fetchee = await originalFetch(...args); | |
return new Proxy(fetchee, {}); | |
}; | |
new Proxy(target, { |
This file contains 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
// new | |
return (...args) => { | |
try { | |
return handler.call(this, ...args); | |
} catch(e) { | |
return this.onError(e); | |
} | |
}; | |
// old school |
This file contains 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
// http://youmightnotneedjquery.com/ | |
// DOM manipulation | |
// create element | |
createElement(tagName, options) // tag null = ??? | |
createComment(str) | |
createDocumentFragment() // create a sub-dom tree https://devdocs.io/dom/document/createdocumentfragment | |
doc = ocument.parseHTMLUnsafe() |
This file contains 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
// https://github.com/Offirmo/blog/blob/gh-pages/tosort/javascript-daily/mod-floating.md | |
const floating = require('floating.js) | |
floating({ | |
content: '<span style="color: snow">❄</span>', | |
number: 25, | |
direction: 'reverse', | |
size: [0.5, 2.5], | |
}) |