@xh/hoist 75.0.0-SNAPSHOT.1753468710177 → 75.0.0-SNAPSHOT.1753474244586

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.
@@ -40,7 +40,7 @@ import {
40
40
  TrackService,
41
41
  WebSocketService
42
42
  } from '@xh/hoist/svc';
43
- import {checkMinVersion, throwIf} from '@xh/hoist/utils/js';
43
+ import {checkMinVersion, createSingleton, throwIf} from '@xh/hoist/utils/js';
44
44
  import {compact, isEmpty} from 'lodash';
45
45
  import {AboutDialogModel} from './AboutDialogModel';
46
46
  import {BannerSourceModel} from './BannerSourceModel';
@@ -197,7 +197,7 @@ export class AppContainerModel extends HoistModel {
197
197
 
198
198
  // Check auth, locking out, or showing login if possible
199
199
  this.setAppState('AUTHENTICATING');
200
- XH.authModel = new this.appSpec.authModelClass();
200
+ XH.authModel = createSingleton(this.appSpec.authModelClass);
201
201
  const isAuthenticated = await XH.authModel.completeAuthAsync();
202
202
  if (!isAuthenticated) {
203
203
  throwIf(
@@ -287,8 +287,7 @@ export class AppContainerModel extends HoistModel {
287
287
  await wait(XH.isDevelopmentMode ? 300 : 1);
288
288
 
289
289
  this.setAppState('INITIALIZING_APP');
290
- const modelClass: any = this.appSpec.modelClass;
291
- this.appModel = modelClass.instance = new modelClass();
290
+ this.appModel = createSingleton(this.appSpec.modelClass);
292
291
  await this.appModel.initAsync();
293
292
  this.startRouter();
294
293
  this.startOptionsDialog();
@@ -44,6 +44,16 @@ export declare function warnIf(condition: any, message: any): void;
44
44
  * Log an error to the console if a condition evaluates as truthy.
45
45
  */
46
46
  export declare function errorIf(condition: any, message: any): void;
47
+ /**
48
+ * Instantiate a singleton object of a class, and place a reference to the created
49
+ * object in a static property on the class.
50
+ *
51
+ * This pattern is useful to allow gaining typed references to the singleton via import
52
+ * and is used for creating the singleton HoistServices, AuthModel, and AppModel.
53
+ *
54
+ * @param clazz -- Class (i.e. Constructor) of singleton object to be created.
55
+ */
56
+ export declare function createSingleton<T>(clazz: new () => T): T;
47
57
  export interface APIWarnOptions {
48
58
  /**
49
59
  * If provided and undefined, this method will be a no-op.
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import {HoistService, HoistServiceClass, Some, XH} from '@xh/hoist/core';
8
8
  import {instanceManager} from '@xh/hoist/core/impl/InstanceManager';
9
- import {throwIf} from '@xh/hoist/utils/js';
9
+ import {createSingleton, throwIf} from '@xh/hoist/utils/js';
10
10
  import {camelCase, castArray} from 'lodash';
11
11
 
12
12
  /**
@@ -30,7 +30,7 @@ export async function installServicesAsync(serviceClasses: Some<HoistServiceClas
30
30
  const notSvc = serviceClasses.find((it: any) => !it.isHoistService);
31
31
  throwIf(notSvc, `Cannot initialize ${notSvc?.name} - does not extend HoistService`);
32
32
 
33
- const svcs = serviceClasses.map(serviceClass => new serviceClass());
33
+ const svcs = serviceClasses.map(c => createSingleton(c));
34
34
  await initServicesInternalAsync(svcs);
35
35
 
36
36
  svcs.forEach(svc => {
@@ -43,7 +43,6 @@ export async function installServicesAsync(serviceClasses: Some<HoistServiceClas
43
43
  install the same service twice.`
44
44
  );
45
45
  XH[name] = svc;
46
- (clazz as any).instance = svc;
47
46
  instanceManager.registerService(svc);
48
47
  });
49
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xh/hoist",
3
- "version": "75.0.0-SNAPSHOT.1753468710177",
3
+ "version": "75.0.0-SNAPSHOT.1753474244586",
4
4
  "description": "Hoist add-on for building and deploying React Applications.",
5
5
  "repository": "github:xh/hoist-react",
6
6
  "homepage": "https://xh.io",