@memberjunction/react-runtime 6.2.0-edge.4 → 6.2.0-edge.5
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/.turbo/turbo-build.log +13 -13
- package/CHANGELOG.md +46 -0
- package/dist/registry/component-registry-service.d.ts +2 -1
- package/dist/registry/component-registry-service.d.ts.map +1 -1
- package/dist/registry/component-registry-service.js +20 -8
- package/dist/registry/component-registry-service.js.map +1 -1
- package/dist/runtime.umd.js +206 -188
- package/package.json +7 -7
- package/src/__tests__/component-registry-service.test.ts +38 -0
- package/src/registry/component-registry-service.ts +26 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/react-runtime",
|
|
3
|
-
"version": "6.2.0-edge.
|
|
3
|
+
"version": "6.2.0-edge.5",
|
|
4
4
|
"description": "Platform-agnostic React component runtime for MemberJunction. Provides core compilation, registry, and execution capabilities for React components in any JavaScript environment.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
"homepage": "https://github.com/MemberJunction/MJ#readme",
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@babel/standalone": "^7.29.1",
|
|
23
|
-
"@memberjunction/ai-vectors-memory": "6.2.0-edge.
|
|
24
|
-
"@memberjunction/core": "6.2.0-edge.
|
|
25
|
-
"@memberjunction/core-entities": "6.2.0-edge.
|
|
26
|
-
"@memberjunction/global": "6.2.0-edge.
|
|
27
|
-
"@memberjunction/graphql-dataprovider": "6.2.0-edge.
|
|
28
|
-
"@memberjunction/interactive-component-types": "6.2.0-edge.
|
|
23
|
+
"@memberjunction/ai-vectors-memory": "6.2.0-edge.5",
|
|
24
|
+
"@memberjunction/core": "6.2.0-edge.5",
|
|
25
|
+
"@memberjunction/core-entities": "6.2.0-edge.5",
|
|
26
|
+
"@memberjunction/global": "6.2.0-edge.5",
|
|
27
|
+
"@memberjunction/graphql-dataprovider": "6.2.0-edge.5",
|
|
28
|
+
"@memberjunction/interactive-component-types": "6.2.0-edge.5",
|
|
29
29
|
"rxjs": "^7.8.2"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { GetGlobalObjectStore } from '@memberjunction/global';
|
|
3
|
+
import { ComponentRegistryService } from '../registry/component-registry-service';
|
|
4
|
+
import type { ComponentCompiler } from '../compiler/component-compiler';
|
|
5
|
+
import type { RuntimeContext } from '../types';
|
|
6
|
+
|
|
7
|
+
describe('ComponentRegistryService singleton', () => {
|
|
8
|
+
const mockCompiler = {} as ComponentCompiler;
|
|
9
|
+
const mockRuntimeContext = {} as RuntimeContext;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
ComponentRegistryService.Reset();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
ComponentRegistryService.Reset();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('stores the singleton instance in GlobalObjectStore and clears it on Reset()', () => {
|
|
20
|
+
const globalStore = GetGlobalObjectStore();
|
|
21
|
+
expect(globalStore?.['___SINGLETON__ComponentRegistryService']).toBeUndefined();
|
|
22
|
+
expect(ComponentRegistryService.Instance).toBeUndefined();
|
|
23
|
+
|
|
24
|
+
const first = ComponentRegistryService.GetInstance(mockCompiler, mockRuntimeContext, false);
|
|
25
|
+
expect(first).toBeInstanceOf(ComponentRegistryService);
|
|
26
|
+
expect(globalStore?.['___SINGLETON__ComponentRegistryService']).toBe(first);
|
|
27
|
+
expect(ComponentRegistryService.Instance).toBe(first);
|
|
28
|
+
expect(ComponentRegistryService.getInstance(mockCompiler, mockRuntimeContext)).toBe(first);
|
|
29
|
+
|
|
30
|
+
ComponentRegistryService.Reset();
|
|
31
|
+
expect(globalStore?.['___SINGLETON__ComponentRegistryService']).toBeUndefined();
|
|
32
|
+
expect(ComponentRegistryService.Instance).toBeUndefined();
|
|
33
|
+
|
|
34
|
+
const second = ComponentRegistryService.GetInstance(mockCompiler, mockRuntimeContext, false);
|
|
35
|
+
expect(second).toBeInstanceOf(ComponentRegistryService);
|
|
36
|
+
expect(second).not.toBe(first);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
RegistryComponentMetadata
|
|
15
15
|
} from './registry-provider';
|
|
16
16
|
import { UserInfo, Metadata, IMetadataProvider } from '@memberjunction/core';
|
|
17
|
-
import { UUIDsEqual } from '@memberjunction/global';
|
|
17
|
+
import { GetGlobalObjectStore, UUIDsEqual } from '@memberjunction/global';
|
|
18
18
|
import {
|
|
19
19
|
MJComponentEntity,
|
|
20
20
|
MJComponentRegistryEntity,
|
|
@@ -59,7 +59,7 @@ export interface IComponentRegistryClient {
|
|
|
59
59
|
* Service for managing component loading from registries with compilation caching
|
|
60
60
|
*/
|
|
61
61
|
export class ComponentRegistryService {
|
|
62
|
-
private static
|
|
62
|
+
private static readonly _globalStoreKey = '___SINGLETON__ComponentRegistryService';
|
|
63
63
|
|
|
64
64
|
// Caches
|
|
65
65
|
private compiledComponentCache = new Map<string, CachedCompiledComponent>();
|
|
@@ -97,9 +97,18 @@ export class ComponentRegistryService {
|
|
|
97
97
|
this.debug = debug;
|
|
98
98
|
this.graphQLClient = graphQLClient;
|
|
99
99
|
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Returns the initialized singleton instance from the Global Object Store, or undefined if not yet created.
|
|
103
|
+
*/
|
|
104
|
+
public static get Instance(): ComponentRegistryService | undefined {
|
|
105
|
+
const g = GetGlobalObjectStore();
|
|
106
|
+
return g ? (g[ComponentRegistryService._globalStoreKey] as ComponentRegistryService | undefined) : undefined;
|
|
107
|
+
}
|
|
100
108
|
|
|
101
109
|
/**
|
|
102
|
-
* Get or create the singleton instance
|
|
110
|
+
* Get or create the singleton instance, backed by the Global Object Store so bundler duplication
|
|
111
|
+
* across execution paths cannot split the cached registry.
|
|
103
112
|
*/
|
|
104
113
|
static GetInstance(
|
|
105
114
|
compiler: ComponentCompiler,
|
|
@@ -107,10 +116,14 @@ export class ComponentRegistryService {
|
|
|
107
116
|
debug: boolean = false,
|
|
108
117
|
graphQLClient?: IComponentRegistryClient
|
|
109
118
|
): ComponentRegistryService {
|
|
110
|
-
|
|
111
|
-
|
|
119
|
+
const g = GetGlobalObjectStore();
|
|
120
|
+
if (g) {
|
|
121
|
+
if (!g[ComponentRegistryService._globalStoreKey]) {
|
|
122
|
+
g[ComponentRegistryService._globalStoreKey] = new ComponentRegistryService(compiler, context, debug, graphQLClient);
|
|
123
|
+
}
|
|
124
|
+
return g[ComponentRegistryService._globalStoreKey] as ComponentRegistryService;
|
|
112
125
|
}
|
|
113
|
-
return ComponentRegistryService
|
|
126
|
+
return new ComponentRegistryService(compiler, context, debug, graphQLClient);
|
|
114
127
|
}
|
|
115
128
|
|
|
116
129
|
/** @deprecated Use {@link GetInstance}. */
|
|
@@ -990,9 +1003,13 @@ export class ComponentRegistryService {
|
|
|
990
1003
|
* Forces new instance creation on next access
|
|
991
1004
|
*/
|
|
992
1005
|
static Reset(): void {
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
1006
|
+
const g = GetGlobalObjectStore();
|
|
1007
|
+
const existing = g ? (g[ComponentRegistryService._globalStoreKey] as ComponentRegistryService | undefined) : undefined;
|
|
1008
|
+
if (existing) {
|
|
1009
|
+
existing.forceClearAll();
|
|
1010
|
+
if (g) {
|
|
1011
|
+
delete g[ComponentRegistryService._globalStoreKey];
|
|
1012
|
+
}
|
|
996
1013
|
}
|
|
997
1014
|
}
|
|
998
1015
|
|