@xh/hoist 75.0.0-SNAPSHOT.1753468710177 → 75.0.0-SNAPSHOT.1753485410401
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/utils/js/LangUtils.ts
CHANGED
|
@@ -143,6 +143,19 @@ export function errorIf(condition: any, message: any) {
|
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
+
/**
|
|
147
|
+
* Instantiate a singleton object of a class, and place a reference to the created
|
|
148
|
+
* object in a static property on the class.
|
|
149
|
+
*
|
|
150
|
+
* This pattern is useful to allow gaining typed references to the singleton via import
|
|
151
|
+
* and is used for creating the singleton HoistServices, AuthModel, and AppModel.
|
|
152
|
+
*
|
|
153
|
+
* @param clazz -- Class (i.e. Constructor) of singleton object to be created.
|
|
154
|
+
*/
|
|
155
|
+
export function createSingleton<T>(clazz: new () => T): T {
|
|
156
|
+
return (clazz['instance'] = new clazz());
|
|
157
|
+
}
|
|
158
|
+
|
|
146
159
|
export interface APIWarnOptions {
|
|
147
160
|
/**
|
|
148
161
|
* If provided and undefined, this method will be a no-op.
|