never refactor just before pushing

This commit is contained in:
Geoff Doty 2021-01-01 22:34:37 -05:00
parent 595e519851
commit c99bf6d00a
5 changed files with 61 additions and 92 deletions

37
dist/anchor.js vendored
View File

@ -1,38 +1,29 @@
function Anchor(fasten = {}, mixins = []) {
const NAMESPACE = `_${Math.random().toString(36).slice(-6)}_`.toUpperCase();
class Anchor { const GLOBAL = window || global || {};
constructor(fasten = {}, mixins = [], debug = false) {
this.namespace = `_${Math.random().toString(36).slice(-6)}_`.toUpperCase();
this.global = window || global; const register = function register(key, value) {
if (GLOBAL[NAMESPACE] && !GLOBAL[NAMESPACE][key]) {
return this.build(fasten, mixins, debug); return GLOBAL[NAMESPACE][key] = value;
}
register(key, value) {
if (this.global[this.namespace] && !this.global[this.namespace][key]) {
return this.global[this.namespace][key] = value;
} }
return false; return false;
} }.bind(GLOBAL[NAMESPACE]);
build(fasten, merges, debug) { function build(fasten, merges, register) {
if (this.global[this.namespace]) { if (GLOBAL[NAMESPACE]) {
return false; return false;
} }
this.global[this.namespace] = fasten; GLOBAL[NAMESPACE] = fasten;
GLOBAL[NAMESPACE]['register'] = register;
merges.forEach((merge) => Object.assign(this.global[this.namespace], merge)); merges.forEach((merge) => Object.assign(GLOBAL[NAMESPACE], merge));
this.register('register', this.register); return GLOBAL[NAMESPACE];
if (!!debug) {
console.log('ANCHOR:FASTEN', this.namespace, this.global[this.namespace]);
}
return this.global[this.namespace];
} }
return build(fasten, mixins, register);
} }
export default Anchor; export default Anchor;

2
dist/anchor.min.js vendored
View File

@ -1 +1 @@
class Anchor{constructor(s={},e=[],t=!1){return this.namespace=`_${Math.random().toString(36).slice(-6)}_`.toUpperCase(),this.global=window||global,this.build(s,e,t)}register(s,e){return!(!this.global[this.namespace]||this.global[this.namespace][s])&&(this.global[this.namespace][s]=e)}build(s,e,t){return!this.global[this.namespace]&&(this.global[this.namespace]=s,e.forEach(s=>Object.assign(this.global[this.namespace],s)),this.register("register",this.register),t&&console.log("ANCHOR:FASTEN",this.namespace,this.global[this.namespace]),this.global[this.namespace])}}export default Anchor; function Anchor(n={},r=[]){const t=`_${Math.random().toString(36).slice(-6)}_`.toUpperCase(),o=window||global||{};return function(n,r,e){return!o[t]&&(o[t]=n,o[t].register=e,r.forEach(n=>Object.assign(o[t],n)),o[t])}(n,r,function(n,r){return!(!o[t]||o[t][n])&&(o[t][n]=r)}.bind(o[t]))}export default Anchor;

38
dist/anchor.umd.js vendored
View File

@ -4,42 +4,32 @@
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.umd = factory()); (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.umd = factory());
}(this, (function () { 'use strict'; }(this, (function () { 'use strict';
function Anchor(fasten = {}, mixins = []) {
const NAMESPACE = `_${Math.random().toString(36).slice(-6)}_`.toUpperCase();
const GLOBAL = window || global || {};
class Anchor { const register = function register(key, value) {
constructor(fasten = {}, mixins = [], debug = false) { if (GLOBAL[NAMESPACE] && !GLOBAL[NAMESPACE][key]) {
this.namespace = `_${Math.random().toString(36).slice(-6)}_`.toUpperCase(); return GLOBAL[NAMESPACE][key] = value;
this.global = window || global;
return this.build(fasten, mixins, debug);
}
register(key, value) {
if (this.global[this.namespace] && !this.global[this.namespace][key]) {
return this.global[this.namespace][key] = value;
} }
return false; return false;
} }.bind(GLOBAL[NAMESPACE]);
build(fasten, merges, debug) { function build(fasten, merges, register) {
if (this.global[this.namespace]) { if (GLOBAL[NAMESPACE]) {
return false; return false;
} }
this.global[this.namespace] = fasten; GLOBAL[NAMESPACE] = fasten;
GLOBAL[NAMESPACE]['register'] = register;
merges.forEach((merge) => Object.assign(this.global[this.namespace], merge)); merges.forEach((merge) => Object.assign(GLOBAL[NAMESPACE], merge));
this.register('register', this.register); return GLOBAL[NAMESPACE];
if (!!debug) {
console.log('ANCHOR:FASTEN', this.namespace, this.global[this.namespace]);
}
return this.global[this.namespace];
} }
return build(fasten, mixins, register);
} }
return Anchor; return Anchor;

View File

@ -1 +1 @@
!function(e,s){"object"==typeof exports&&"undefined"!=typeof module?module.exports=s():"function"==typeof define&&define.amd?define("umd",s):(e="undefined"!=typeof globalThis?globalThis:e||self).umd=s()}(this,function(){"use strict";return class{constructor(e={},s=[],t=!1){return this.namespace=`_${Math.random().toString(36).slice(-6)}_`.toUpperCase(),this.global=window||global,this.build(e,s,t)}register(e,s){return!(!this.global[this.namespace]||this.global[this.namespace][e])&&(this.global[this.namespace][e]=s)}build(e,s,t){return!this.global[this.namespace]&&(this.global[this.namespace]=e,s.forEach(e=>Object.assign(this.global[this.namespace],e)),this.register("register",this.register),t&&console.log("ANCHOR:FASTEN",this.namespace,this.global[this.namespace]),this.global[this.namespace])}}}); !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define("umd",n):(e="undefined"!=typeof globalThis?globalThis:e||self).umd=n()}(this,function(){"use strict";return function(e={},n=[]){const t=`_${Math.random().toString(36).slice(-6)}_`.toUpperCase(),o=window||global||{};return function(e,n,i){return!o[t]&&(o[t]=e,o[t].register=i,n.forEach(e=>Object.assign(o[t],e)),o[t])}(e,n,function(e,n){return!(!o[t]||o[t][e])&&(o[t][e]=n)}.bind(o[t]))}});

View File

@ -1,65 +1,53 @@
/* {Module} v{version} | MIT | https:// */
/** /**
* Tiny global application registry * Tiny global application registry
*/ */
class Anchor { function Anchor(fasten = {}, mixins = []) {
constructor(fasten = {}, mixins = [], debug = false) { // create a unique namespace to avoid collisions
// create a unique namespace to avoid collisions const NAMESPACE = `_${Math.random().toString(36).slice(-6)}_`.toUpperCase();
this.namespace = `_${Math.random().toString(36).slice(-6)}_`.toUpperCase();
// find environments global object // find environments global object
this.global = window || global; const GLOBAL = window || global || {};
// builds anchor instance
return this.build(fasten, mixins, debug);
}
/** /**
* Register * Register
* *
* Helper to extend functionality without overriding existing * Helper to extend functionality without overriding existing
* *
* @param {String} key * @param {String} key
* @param {Any} value * @param {Any} value
*/ */
register(key, value) { const register = function register(key, value) {
if (this.global[this.namespace] && !this.global[this.namespace][key]) { if (GLOBAL[NAMESPACE] && !GLOBAL[NAMESPACE][key]) {
return this.global[this.namespace][key] = value; return GLOBAL[NAMESPACE][key] = value;
} }
return false; return false;
} }.bind(GLOBAL[NAMESPACE]);
/** /**
* Builds the Application Anchor * Builds the Application Anchor
* *
* @param {Object} fasten * @param {Object} fasten
* @param {Array} merges * @param {Array} merges
* @param {Boolean} debug * @param {Boolean} debug
*/ */
build(fasten, merges, debug) { function build(fasten, merges, register) {
if (this.global[this.namespace]) { if (GLOBAL[NAMESPACE]) {
// already initialized // already initialized
return false; return false;
} }
// add to global instance // add to global instance
this.global[this.namespace] = fasten; GLOBAL[NAMESPACE] = fasten;
GLOBAL[NAMESPACE]['register'] = register;
// merge with global instance // merge with global instance
merges.forEach((merge) => Object.assign(this.global[this.namespace], merge)); merges.forEach((merge) => Object.assign(GLOBAL[NAMESPACE], merge));
// app global utils return GLOBAL[NAMESPACE];
this.register('register', this.register); };
if (debug) { return build(fasten, mixins, register);
// eslint-disable-next-line };
console.log('ANCHOR:FASTEN', this.namespace, this.global[this.namespace]);
}
return this.global[this.namespace];
}
}
export default Anchor; export default Anchor;