never refactor just before pushing
This commit is contained in:
parent
595e519851
commit
c99bf6d00a
|
@ -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;
|
||||
|
|
|
@ -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;
|
|
@ -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;
|
||||
|
|
|
@ -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]))}});
|
44
src/index.js
44
src/index.js
|
@ -1,19 +1,12 @@
|
|||
/* {Module} v{version} | MIT | https:// */
|
||||
|
||||
/**
|
||||
* Tiny global application registry
|
||||
*/
|
||||
class Anchor {
|
||||
constructor(fasten = {}, mixins = [], debug = false) {
|
||||
function Anchor(fasten = {}, mixins = []) {
|
||||
// create a unique namespace to avoid collisions
|
||||
this.namespace = `_${Math.random().toString(36).slice(-6)}_`.toUpperCase();
|
||||
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);
|
||||
}
|
||||
const GLOBAL = window || global || {};
|
||||
|
||||
/**
|
||||
* Register
|
||||
|
@ -23,13 +16,13 @@ class Anchor {
|
|||
* @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;
|
||||
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
|
||||
|
@ -38,28 +31,23 @@ class Anchor {
|
|||
* @param {Array} merges
|
||||
* @param {Boolean} debug
|
||||
*/
|
||||
build(fasten, merges, debug) {
|
||||
if (this.global[this.namespace]) {
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue