@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/README.md
CHANGED
|
@@ -289,7 +289,7 @@ available to application code, use the`XH.installServicesAsync()` method. This m
|
|
|
289
289
|
construct, initialize, and install the services as a property on the XH object. Note that there is a
|
|
290
290
|
strict expectation that service classes will be named ending with the word 'Service', e.g.
|
|
291
291
|
`MyCustomService.`. The installed instance in this case would then be made available to application
|
|
292
|
-
code as `XH.myCustomService
|
|
292
|
+
code as `XH.myCustomService`.
|
|
293
293
|
|
|
294
294
|
Many core Hoist features are exposed on the client via services such as `PrefService`,
|
|
295
295
|
`ConfigService`, and `IdentityService`. See these examples for a better understanding of the kind of
|
|
@@ -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 =
|
|
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
|
-
|
|
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(
|
|
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.
|
|
3
|
+
"version": "75.0.0-SNAPSHOT.1753485410401",
|
|
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",
|