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 {
constructor(fasten = {}, mixins = [], debug = false) {
this.namespace = `_${Math.random().toString(36).slice(-6)}_`.toUpperCase();
const GLOBAL = window || global || {};
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;
const register = function register(key, value) {
if (GLOBAL[NAMESPACE] && !GLOBAL[NAMESPACE][key]) {
return GLOBAL[NAMESPACE][key] = value;
}
return false;
}
}.bind(GLOBAL[NAMESPACE]);
build(fasten, merges, debug) {
if (this.global[this.namespace]) {
function build(fasten, merges, register) {
if (GLOBAL[NAMESPACE]) {
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);
if (!!debug) {
console.log('ANCHOR:FASTEN', this.namespace, this.global[this.namespace]);
}
return this.global[this.namespace];
return GLOBAL[NAMESPACE];
}
return build(fasten, mixins, register);
}
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());
}(this, (function () { 'use strict';
function Anchor(fasten = {}, mixins = []) {
const NAMESPACE = `_${Math.random().toString(36).slice(-6)}_`.toUpperCase();
const GLOBAL = window || global || {};
class Anchor {
constructor(fasten = {}, mixins = [], debug = false) {
this.namespace = `_${Math.random().toString(36).slice(-6)}_`.toUpperCase();
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;
const register = function register(key, value) {
if (GLOBAL[NAMESPACE] && !GLOBAL[NAMESPACE][key]) {
return GLOBAL[NAMESPACE][key] = value;
}
return false;
}
}.bind(GLOBAL[NAMESPACE]);
build(fasten, merges, debug) {
if (this.global[this.namespace]) {
function build(fasten, merges, register) {
if (GLOBAL[NAMESPACE]) {
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);
if (!!debug) {
console.log('ANCHOR:FASTEN', this.namespace, this.global[this.namespace]);
}
return this.global[this.namespace];
return GLOBAL[NAMESPACE];
}
return build(fasten, mixins, register);
}
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
*/
class Anchor {
constructor(fasten = {}, mixins = [], debug = false) {
// create a unique namespace to avoid collisions
this.namespace = `_${Math.random().toString(36).slice(-6)}_`.toUpperCase();
function Anchor(fasten = {}, mixins = []) {
// create a unique namespace to avoid collisions
const NAMESPACE = `_${Math.random().toString(36).slice(-6)}_`.toUpperCase();
// find environments global object
this.global = window || global;
// builds anchor instance
return this.build(fasten, mixins, debug);
}
// find environments global object
const GLOBAL = window || global || {};
/**
* Register
*
* Helper to extend functionality without overriding existing
*
* @param {String} key
* @param {Any} value
*/
register(key, value) {
if (this.global[this.namespace] && !this.global[this.namespace][key]) {
return this.global[this.namespace][key] = value;
* Register
*
* Helper to extend functionality without overriding existing
*
* @param {String} key
* @param {Any} value
*/
const register = function register(key, value) {
if (GLOBAL[NAMESPACE] && !GLOBAL[NAMESPACE][key]) {
return GLOBAL[NAMESPACE][key] = value;
}
return false;
}
}.bind(GLOBAL[NAMESPACE]);
/**
* Builds the Application Anchor
*
* @param {Object} fasten
* @param {Array} merges
* @param {Boolean} debug
*/
build(fasten, merges, debug) {
if (this.global[this.namespace]) {
* Builds the Application Anchor
*
* @param {Object} fasten
* @param {Array} merges
* @param {Boolean} debug
*/
function build(fasten, merges, register) {
if (GLOBAL[NAMESPACE]) {
// already initialized
return false;
}
// add to global instance
this.global[this.namespace] = fasten;
GLOBAL[NAMESPACE] = fasten;
GLOBAL[NAMESPACE]['register'] = register;
// 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
this.register('register', this.register);
return GLOBAL[NAMESPACE];
};
if (debug) {
// eslint-disable-next-line
console.log('ANCHOR:FASTEN', this.namespace, this.global[this.namespace]);
}
return this.global[this.namespace];
}
}
return build(fasten, mixins, register);
};
export default Anchor;