# 1.0.32
- Fixes: - helpers.singleton: work with `Symbol.for` - symbols.symbols: work with `Symbol.for`
This commit is contained in:
parent
daaa0fd51a
commit
ee1d690dc8
@ -41,3 +41,8 @@ Inital commit, which is working with the browser
|
|||||||
# 1.0.31
|
# 1.0.31
|
||||||
- Modified:
|
- Modified:
|
||||||
- helpers.singleton: Prevent using symbols, to make global version work with local version.
|
- helpers.singleton: Prevent using symbols, to make global version work with local version.
|
||||||
|
|
||||||
|
# 1.0.32
|
||||||
|
- Fixes:
|
||||||
|
- helpers.singleton: work with `Symbol.for`
|
||||||
|
- symbols.symbols: work with `Symbol.for`
|
||||||
|
@ -1 +1 @@
|
|||||||
1.0.31
|
1.0.32
|
@ -4,6 +4,9 @@
|
|||||||
* @desc [description]
|
* @desc [description]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const NOPE_SYMBOL = Symbol.for("nope");
|
||||||
|
const SINGLETONS_SYMBOL = Symbol.for("singletons");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to get a singleton. To create the singleton, the parameter *create* is used. This will be called once.
|
* Function to get a singleton. To create the singleton, the parameter *create* is used. This will be called once.
|
||||||
* The singleton will be stored as *global* variable and can be accessed by the identifier
|
* The singleton will be stored as *global* variable and can be accessed by the identifier
|
||||||
@ -22,19 +25,19 @@ export function getSingleton<T>(
|
|||||||
instance: T;
|
instance: T;
|
||||||
setInstance: (value: T) => void;
|
setInstance: (value: T) => void;
|
||||||
} {
|
} {
|
||||||
if (!global["nope"]) {
|
if (!global[NOPE_SYMBOL]) {
|
||||||
global["nope"] = {
|
global[NOPE_SYMBOL] = {
|
||||||
singletons: {},
|
singletons: {},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!global["nope"]["singletons"]) {
|
if (!global[NOPE_SYMBOL][SINGLETONS_SYMBOL]) {
|
||||||
global["nope"]["singletons"] = {};
|
global[NOPE_SYMBOL][SINGLETONS_SYMBOL] = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract all
|
// Extract all
|
||||||
const globalSingletons = Object.getOwnPropertyNames(
|
const globalSingletons = Object.getOwnPropertyNames(
|
||||||
global["nope"]["singletons"]
|
global[NOPE_SYMBOL][SINGLETONS_SYMBOL]
|
||||||
);
|
);
|
||||||
|
|
||||||
// create a unique, global symbol name
|
// create a unique, global symbol name
|
||||||
@ -48,16 +51,19 @@ export function getSingleton<T>(
|
|||||||
globalSingletons.indexOf(IDENTIFIER_DISPATCHER_CONTAINER) > -1;
|
globalSingletons.indexOf(IDENTIFIER_DISPATCHER_CONTAINER) > -1;
|
||||||
|
|
||||||
if (!hasContainer) {
|
if (!hasContainer) {
|
||||||
global["nope"]["singletons"][IDENTIFIER_DISPATCHER_CONTAINER] = create();
|
global[NOPE_SYMBOL][SINGLETONS_SYMBOL][IDENTIFIER_DISPATCHER_CONTAINER] =
|
||||||
|
create();
|
||||||
}
|
}
|
||||||
|
|
||||||
const ret: {
|
const ret: {
|
||||||
instance: T;
|
instance: T;
|
||||||
setInstance: (value: T) => void;
|
setInstance: (value: T) => void;
|
||||||
} = {
|
} = {
|
||||||
instance: global["nope"]["singletons"][IDENTIFIER_DISPATCHER_CONTAINER],
|
instance:
|
||||||
|
global[NOPE_SYMBOL][SINGLETONS_SYMBOL][IDENTIFIER_DISPATCHER_CONTAINER],
|
||||||
setInstance: (value: T) => {
|
setInstance: (value: T) => {
|
||||||
global["nope"]["singletons"][IDENTIFIER_DISPATCHER_CONTAINER] = value;
|
global[NOPE_SYMBOL][SINGLETONS_SYMBOL][IDENTIFIER_DISPATCHER_CONTAINER] =
|
||||||
|
value;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -65,7 +71,9 @@ export function getSingleton<T>(
|
|||||||
// ------------------------
|
// ------------------------
|
||||||
Object.defineProperty(ret, "instance", {
|
Object.defineProperty(ret, "instance", {
|
||||||
get: function () {
|
get: function () {
|
||||||
return global["nope"]["singletons"][IDENTIFIER_DISPATCHER_CONTAINER];
|
return global[NOPE_SYMBOL][SINGLETONS_SYMBOL][
|
||||||
|
IDENTIFIER_DISPATCHER_CONTAINER
|
||||||
|
];
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -6,9 +6,9 @@
|
|||||||
* @desc [description]
|
* @desc [description]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const DISPATCHER_INSTANCE = Symbol("nope.dispatcher.instance");
|
export const DISPATCHER_INSTANCE = Symbol.for("nope.dispatcher.instance");
|
||||||
export const DISPATCHER_OPTIONS = Symbol("nope.dispatcher.options");
|
export const DISPATCHER_OPTIONS = Symbol.for("nope.dispatcher.options");
|
||||||
export const OBSERVABLE_FACTORY = Symbol("nope.observable.factory");
|
export const OBSERVABLE_FACTORY = Symbol.for("nope.observable.factory");
|
||||||
export const OBSERVABLE_INSTANCE = Symbol("nope.observable.instance");
|
export const OBSERVABLE_INSTANCE = Symbol.for("nope.observable.instance");
|
||||||
export const COMMUNICATION_LAYER = Symbol("nope.communication.layer");
|
export const COMMUNICATION_LAYER = Symbol.for("nope.communication.layer");
|
||||||
export const LOADER = Symbol("nope.package.loader");
|
export const LOADER = Symbol.for("nope.package.loader");
|
||||||
|
Loading…
Reference in New Issue
Block a user