Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@memberjunction/global

Package Overview
Dependencies
Maintainers
4
Versions
204
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@memberjunction/global - npm Package Compare versions

Comparing version 1.4.0 to 1.4.1

dist/BaseSingleton.d.ts

2

dist/ClassFactory.d.ts

@@ -25,3 +25,3 @@ /*******************************************************************************************************

* @param key A key can be used to differentiate registrations for the same base class/sub-class combination. For example, in the case of BaseEntity and Entity object subclasses we'll have a LOT of entries and we want to get the highest priority registered sub-class for a specific key. In that case, the key is the entity name, but the key can be any value you want to use to differentiate registrations.
* @param priority Higher priority registrations will be used over lower priority registrations. If there are multiple registrations for a given base class/sub-class/key combination, the one with the highest priority will be used. If there are multiple registrations with the same priority, the last one registered will be used.
* @param priority Higher priority registrations will be used over lower priority registrations. If there are multiple registrations for a given base class/sub-class/key combination, the one with the highest priority will be used. If there are multiple registrations with the same priority, the last one registered will be used. Finally, if you do NOT provide this setting, the order of registrations will increment the priority automatically so dependency injection will typically care care of this. That is, in order for Class B, a subclass of Class A, to be registered properly, Class A code has to already have been loaded and therefore Class A's RegisterClass decorator was run. In that scenario, if neither Class A or B has a priority setting, Class A would be 1 and Class B would be 2 automatically. For this reason, you only need to explicitly set priority if you want to do something atypical as this mechanism normally will solve for setting the priority correctly based on the furthest descendant class that is registered.
*/

@@ -28,0 +28,0 @@ Register(baseClass: any, subClass: any, key?: string, priority?: number): void;

@@ -27,3 +27,3 @@ "use strict";

* @param key A key can be used to differentiate registrations for the same base class/sub-class combination. For example, in the case of BaseEntity and Entity object subclasses we'll have a LOT of entries and we want to get the highest priority registered sub-class for a specific key. In that case, the key is the entity name, but the key can be any value you want to use to differentiate registrations.
* @param priority Higher priority registrations will be used over lower priority registrations. If there are multiple registrations for a given base class/sub-class/key combination, the one with the highest priority will be used. If there are multiple registrations with the same priority, the last one registered will be used.
* @param priority Higher priority registrations will be used over lower priority registrations. If there are multiple registrations for a given base class/sub-class/key combination, the one with the highest priority will be used. If there are multiple registrations with the same priority, the last one registered will be used. Finally, if you do NOT provide this setting, the order of registrations will increment the priority automatically so dependency injection will typically care care of this. That is, in order for Class B, a subclass of Class A, to be registered properly, Class A code has to already have been loaded and therefore Class A's RegisterClass decorator was run. In that scenario, if neither Class A or B has a priority setting, Class A would be 1 and Class B would be 2 automatically. For this reason, you only need to explicitly set priority if you want to do something atypical as this mechanism normally will solve for setting the priority correctly based on the furthest descendant class that is registered.
*/

@@ -34,7 +34,20 @@ Register(baseClass, subClass, key = null, priority = 0) {

const registrations = this.GetAllRegistrations(baseClass, key);
// validate to make sure that the comabintion of base class and key for the provided priority # is not already registered, if it is, then throw an exception
const existing = registrations.filter(r => r.Priority === priority);
if (existing && existing.length > 0) {
console.warn(`*** ClassFactory.Register: Registering class ${subClass.name} for base class ${baseClass.name} and key/priority ${key}/${priority}. ${existing.length} registrations already exist for that combination. While this is allowed it is not desired and when matching class requests occur, we will simply use the LAST registration we happen to have which can lead to unintended behavior. ***`);
if (priority > 0) {
// validate to make sure that the comabination of base class and key for the provided priority # is not already registered, if it is, then print a warning
const existing = registrations.filter(r => r.Priority === priority);
if (existing && existing.length > 0) {
console.warn(`*** ClassFactory.Register: Registering class ${subClass.name} for base class ${baseClass.name} and key/priority ${key}/${priority}. ${existing.length} registrations already exist for that combination. While this is allowed it is not desired and when matching class requests occur, we will simply use the LAST registration we happen to have which can lead to unintended behavior. ***`);
}
}
else if (priority === 0 || priority === null || priority === undefined) {
// when priority is not provided or is zero, which is logically the same, check to see what the highest earlier registration was and increment by 1
// this automatically makes the most recent registration higher, IF IT DIDN'T ALREADY have a priority explicitly set
let highestPriority = 0;
for (let i = 0; i < registrations.length; i++) {
if (registrations[i].Priority > highestPriority)
highestPriority = registrations[i].Priority;
}
// now set the priority to one higher than the highest priority we found
priority = highestPriority + 1;
}
// this combination of baseclass/key/priority is NOT already registered.

@@ -41,0 +54,0 @@ let reg = new ClassRegistration();

@@ -5,2 +5,3 @@ import * as MJ from './interface';

import { ObjectCache } from './ObjectCache';
import { BaseSingleton } from './BaseSingleton';
export { ClassFactory, ClassRegistration } from './ClassFactory';

@@ -10,6 +11,7 @@ export * from './interface';

export * from './ObjectCache';
export * from './BaseSingleton';
/**
* Global class used for coordinating events, creating class instances, and managing components across MemberJunction
*/
export declare class MJGlobal {
export declare class MJGlobal extends BaseSingleton<MJGlobal> {
private _eventsSubject;

@@ -19,3 +21,2 @@ private _eventsReplaySubject;

private _eventsReplay$;
private _globalObjectKey;
private _components;

@@ -25,3 +26,7 @@ private static _instance;

private _properties;
constructor();
private constructor();
/**
* Returns the global instance of the MJGlobal class. This is a singleton class, so there is only one instance of it in the application. Do not directly create new instances of MJGlobal, always use this method to get the instance.
*/
static get Instance(): MJGlobal;
RegisterComponent(component: MJ.IMJComponent): void;

@@ -44,6 +49,2 @@ /**

/**
* Returns the global instance of the MJGlobal class. This is a singleton class, so there is only one instance of it in the application. Do not directly create new instances of MJGlobal, always use this method to get the instance.
*/
static get Instance(): MJGlobal;
/**
* Returns the instance of ClassFactory you should use in your application. Access this via the MJGlobal.Instance.ClassFactory property.

@@ -56,3 +57,2 @@ */

get Properties(): MJ.MJGlobalProperty[];
GetGlobalObjectStore(): any;
private _objectCache;

@@ -68,3 +68,3 @@ /**

* @param key a string that is later used to retrieve a given registration - this should be unique for each baseClass/key combination, if multiple registrations exist for a given baseClass/key combination, the highest priority registration will be used to create class instances
* @param priority the higher the number the more priority a registration has. If there are multiple registrations for a given combination of baseClass/key the highest priority registration will be used to create class instances
* @param priority Higher priority registrations will be used over lower priority registrations. If there are multiple registrations for a given base class/sub-class/key combination, the one with the highest priority will be used. If there are multiple registrations with the same priority, the last one registered will be used. Finally, if you do NOT provide this setting, the order of registrations will increment the priority automatically so dependency injection will typically care care of this. That is, in order for Class B, a subclass of Class A, to be registered properly, Class A code has to already have been loaded and therefore Class A's RegisterClass decorator was run. In that scenario, if neither Class A or B has a priority setting, Class A would be 1 and Class B would be 2 automatically. For this reason, you only need to explicitly set priority if you want to do something atypical as this mechanism normally will solve for setting the priority correctly based on the furthest descendant class that is registered.
* @returns an instance of the class that was registered for the combination of baseClass/key (with highest priority if more than one)

@@ -71,0 +71,0 @@ */

@@ -18,6 +18,6 @@ "use strict";

exports.RegisterClass = exports.MJGlobal = exports.ClassRegistration = exports.ClassFactory = void 0;
const util_1 = require("./util");
const rxjs_1 = require("rxjs");
const ClassFactory_1 = require("./ClassFactory");
const ObjectCache_1 = require("./ObjectCache");
const BaseSingleton_1 = require("./BaseSingleton");
var ClassFactory_2 = require("./ClassFactory");

@@ -29,7 +29,9 @@ Object.defineProperty(exports, "ClassFactory", { enumerable: true, get: function () { return ClassFactory_2.ClassFactory; } });

__exportStar(require("./ObjectCache"), exports);
__exportStar(require("./BaseSingleton"), exports);
/**
* Global class used for coordinating events, creating class instances, and managing components across MemberJunction
*/
class MJGlobal {
class MJGlobal extends BaseSingleton_1.BaseSingleton {
constructor() {
super('MJGlobalInstance');
// subjects for observables to handle eventing

@@ -41,3 +43,2 @@ this._eventsSubject = new rxjs_1.Subject();

this._eventsReplay$ = this._eventsReplaySubject.asObservable();
this._globalObjectKey = 'MJGlobalInstance';
this._components = [];

@@ -47,20 +48,9 @@ this._classFactory = new ClassFactory_1.ClassFactory();

this._objectCache = new ObjectCache_1.ObjectCache();
if (MJGlobal._instance)
return MJGlobal._instance;
else {
const g = (0, util_1.GetGlobalObjectStore)();
if (g && g[this._globalObjectKey]) {
MJGlobal._instance = g[this._globalObjectKey];
return MJGlobal._instance;
}
// finally, if we get here, we are the first instance of this class, so create it
if (!MJGlobal._instance) {
MJGlobal._instance = this;
// try to put this in global object store if there is a window/e.g. we're in a browser, a global object, we're in node, etc...
if (g)
g[this._globalObjectKey] = MJGlobal._instance;
return this;
}
}
}
/**
* Returns the global instance of the MJGlobal class. This is a singleton class, so there is only one instance of it in the application. Do not directly create new instances of MJGlobal, always use this method to get the instance.
*/
static get Instance() {
return super.getInstance('MJGlobalInstance');
}
RegisterComponent(component) {

@@ -97,10 +87,2 @@ this._components.push(component);

/**
* Returns the global instance of the MJGlobal class. This is a singleton class, so there is only one instance of it in the application. Do not directly create new instances of MJGlobal, always use this method to get the instance.
*/
static get Instance() {
if (!MJGlobal._instance)
MJGlobal._instance = new MJGlobal();
return MJGlobal._instance;
}
/**
* Returns the instance of ClassFactory you should use in your application. Access this via the MJGlobal.Instance.ClassFactory property.

@@ -117,5 +99,2 @@ */

}
GetGlobalObjectStore() {
return (0, util_1.GetGlobalObjectStore)(); // wrap the function in a method here so that other modules can use it easily.
}
/**

@@ -133,3 +112,3 @@ * ObjectCache can be used to cache objects as needed by any application in memory. These objects are NOT persisted to disk or any other storage medium, so they are only good for the lifetime of the application

* @param key a string that is later used to retrieve a given registration - this should be unique for each baseClass/key combination, if multiple registrations exist for a given baseClass/key combination, the highest priority registration will be used to create class instances
* @param priority the higher the number the more priority a registration has. If there are multiple registrations for a given combination of baseClass/key the highest priority registration will be used to create class instances
* @param priority Higher priority registrations will be used over lower priority registrations. If there are multiple registrations for a given base class/sub-class/key combination, the one with the highest priority will be used. If there are multiple registrations with the same priority, the last one registered will be used. Finally, if you do NOT provide this setting, the order of registrations will increment the priority automatically so dependency injection will typically care care of this. That is, in order for Class B, a subclass of Class A, to be registered properly, Class A code has to already have been loaded and therefore Class A's RegisterClass decorator was run. In that scenario, if neither Class A or B has a priority setting, Class A would be 1 and Class B would be 2 automatically. For this reason, you only need to explicitly set priority if you want to do something atypical as this mechanism normally will solve for setting the priority correctly based on the furthest descendant class that is registered.
* @returns an instance of the class that was registered for the combination of baseClass/key (with highest priority if more than one)

@@ -136,0 +115,0 @@ */

/**
* The Global Object Store is a place to store global objects that need to be shared across the application. Depending on the execution environment, this could be the window object in a browser, or the global object in a node environment.
* This function will return the appropriate object based on the environment.
* The Global Object Store is a place to store global objects that need to be shared across the application. Depending on the execution environment, this could be the window object in a browser, or the global object in a node environment, or something else in other contexts. The key here is that in some cases static variables are not truly shared
* because it is possible that a given class might have copies of its code in multiple paths in a deployed application. This approach ensures that no matter how many code copies might exist, there is only one instance of the object in question by using the Global Object Store.
* @returns

@@ -5,0 +5,0 @@ */

@@ -5,4 +5,4 @@ "use strict";

/**
* The Global Object Store is a place to store global objects that need to be shared across the application. Depending on the execution environment, this could be the window object in a browser, or the global object in a node environment.
* This function will return the appropriate object based on the environment.
* The Global Object Store is a place to store global objects that need to be shared across the application. Depending on the execution environment, this could be the window object in a browser, or the global object in a node environment, or something else in other contexts. The key here is that in some cases static variables are not truly shared
* because it is possible that a given class might have copies of its code in multiple paths in a deployed application. This approach ensures that no matter how many code copies might exist, there is only one instance of the object in question by using the Global Object Store.
* @returns

@@ -9,0 +9,0 @@ */

{
"name": "@memberjunction/global",
"version": "1.4.0",
"version": "1.4.1",
"description": "MemberJunction: Global Object - Needed for ALL other MJ components",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc