@memberjunction/react-runtime 2.77.0 → 2.79.0
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 +1 -1
- package/CHANGELOG.md +17 -0
- package/dist/compiler/component-compiler.d.ts +2 -0
- package/dist/compiler/component-compiler.d.ts.map +1 -1
- package/dist/compiler/component-compiler.js +19 -12
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -25
- package/dist/runtime/index.d.ts +0 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +1 -9
- package/dist/runtime/react-root-manager.d.ts.map +1 -1
- package/dist/runtime/react-root-manager.js +1 -2
- package/dist/utilities/resource-manager.d.ts +6 -4
- package/dist/utilities/resource-manager.d.ts.map +1 -1
- package/dist/utilities/resource-manager.js +82 -31
- package/package.json +4 -4
- package/src/compiler/component-compiler.ts +32 -13
- package/src/index.ts +0 -10
- package/src/runtime/index.ts +0 -10
- package/src/runtime/react-root-manager.ts +2 -3
- package/src/utilities/resource-manager.ts +106 -40
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/runtime/component-wrapper.d.ts +0 -18
- package/dist/runtime/component-wrapper.d.ts.map +0 -1
- package/dist/runtime/component-wrapper.js +0 -108
- package/src/runtime/component-wrapper.ts +0 -249
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @memberjunction/react-runtime
|
|
2
2
|
|
|
3
|
+
## 2.79.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [907e73f]
|
|
8
|
+
- @memberjunction/global@2.79.0
|
|
9
|
+
- @memberjunction/core@2.79.0
|
|
10
|
+
- @memberjunction/interactive-component-types@2.79.0
|
|
11
|
+
|
|
12
|
+
## 2.78.0
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- @memberjunction/interactive-component-types@2.78.0
|
|
17
|
+
- @memberjunction/core@2.78.0
|
|
18
|
+
- @memberjunction/global@2.78.0
|
|
19
|
+
|
|
3
20
|
## 2.77.0
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
|
@@ -2,6 +2,7 @@ import { CompileOptions, CompilationResult, CompilerConfig } from '../types';
|
|
|
2
2
|
export declare class ComponentCompiler {
|
|
3
3
|
private config;
|
|
4
4
|
private compilationCache;
|
|
5
|
+
private cacheAccessOrder;
|
|
5
6
|
private babelInstance;
|
|
6
7
|
constructor(config?: Partial<CompilerConfig>);
|
|
7
8
|
setBabelInstance(babel: any): void;
|
|
@@ -12,6 +13,7 @@ export declare class ComponentCompiler {
|
|
|
12
13
|
private validateCompileOptions;
|
|
13
14
|
private generateComponentId;
|
|
14
15
|
private getCachedComponent;
|
|
16
|
+
private createCacheKey;
|
|
15
17
|
private cacheComponent;
|
|
16
18
|
private createCompilationError;
|
|
17
19
|
clearCache(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-compiler.d.ts","sourceRoot":"","sources":["../../src/compiler/component-compiler.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,cAAc,EAEd,iBAAiB,EACjB,cAAc,EAGf,MAAM,UAAU,CAAC;AAoBlB,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,gBAAgB,CAAiC;IACzD,OAAO,CAAC,aAAa,CAAM;gBAMf,MAAM,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC;IAS5C,gBAAgB,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI;IAS5B,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAqElE,OAAO,CAAC,kBAAkB;IAgC1B,OAAO,CAAC,iBAAiB;IAoCzB,OAAO,CAAC,sBAAsB;
|
|
1
|
+
{"version":3,"file":"component-compiler.d.ts","sourceRoot":"","sources":["../../src/compiler/component-compiler.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,cAAc,EAEd,iBAAiB,EACjB,cAAc,EAGf,MAAM,UAAU,CAAC;AAoBlB,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,gBAAgB,CAAiC;IACzD,OAAO,CAAC,gBAAgB,CAAW;IACnC,OAAO,CAAC,aAAa,CAAM;gBAMf,MAAM,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC;IAS5C,gBAAgB,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI;IAS5B,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAqElE,OAAO,CAAC,kBAAkB;IAgC1B,OAAO,CAAC,iBAAiB;IAoCzB,OAAO,CAAC,sBAAsB;IA8D9B,OAAO,CAAC,sBAAsB;IAiE9B,OAAO,CAAC,mBAAmB;IAU3B,OAAO,CAAC,kBAAkB;IAY1B,OAAO,CAAC,cAAc;IAgBtB,OAAO,CAAC,cAAc;IAkBtB,OAAO,CAAC,sBAAsB;IAa9B,UAAU,IAAI,IAAI;IAQlB,YAAY,IAAI,MAAM;IAQtB,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI;CAGpD"}
|
|
@@ -23,7 +23,7 @@ class ComponentCompiler {
|
|
|
23
23
|
const startTime = Date.now();
|
|
24
24
|
try {
|
|
25
25
|
if (this.config.cache) {
|
|
26
|
-
const cached = this.getCachedComponent(options.componentName);
|
|
26
|
+
const cached = this.getCachedComponent(options.componentName, options.componentCode);
|
|
27
27
|
if (cached) {
|
|
28
28
|
return {
|
|
29
29
|
success: true,
|
|
@@ -43,7 +43,7 @@ class ComponentCompiler {
|
|
|
43
43
|
warnings: []
|
|
44
44
|
};
|
|
45
45
|
if (this.config.cache) {
|
|
46
|
-
this.cacheComponent(compiledComponent);
|
|
46
|
+
this.cacheComponent(compiledComponent, options.componentCode);
|
|
47
47
|
}
|
|
48
48
|
return {
|
|
49
49
|
success: true,
|
|
@@ -114,7 +114,8 @@ class ComponentCompiler {
|
|
|
114
114
|
return (context, styles = {}) => {
|
|
115
115
|
const { React, ReactDOM, libraries = {} } = context;
|
|
116
116
|
const createComponentFn = factoryCreator(React, ReactDOM, React.useState, React.useEffect, React.useCallback, React.useMemo, React.useRef, React.useContext, React.useReducer, React.useLayoutEffect, libraries, styles, console);
|
|
117
|
-
|
|
117
|
+
const Component = createComponentFn(React, ReactDOM, React.useState, React.useEffect, React.useCallback, React.useMemo, React.useRef, React.useContext, React.useReducer, React.useLayoutEffect, libraries, styles, console);
|
|
118
|
+
return Component;
|
|
118
119
|
};
|
|
119
120
|
}
|
|
120
121
|
catch (error) {
|
|
@@ -160,20 +161,26 @@ class ComponentCompiler {
|
|
|
160
161
|
generateComponentId(componentName) {
|
|
161
162
|
return `${componentName}_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
162
163
|
}
|
|
163
|
-
getCachedComponent(componentName) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
164
|
+
getCachedComponent(componentName, code) {
|
|
165
|
+
const cacheKey = this.createCacheKey(componentName, code);
|
|
166
|
+
return this.compilationCache.get(cacheKey);
|
|
167
|
+
}
|
|
168
|
+
createCacheKey(componentName, code) {
|
|
169
|
+
let hash = 0;
|
|
170
|
+
for (let i = 0; i < code.length; i++) {
|
|
171
|
+
const char = code.charCodeAt(i);
|
|
172
|
+
hash = ((hash << 5) - hash) + char;
|
|
173
|
+
hash = hash & hash;
|
|
174
|
+
}
|
|
175
|
+
return `${componentName}_${hash.toString(36)}`;
|
|
170
176
|
}
|
|
171
|
-
cacheComponent(component) {
|
|
177
|
+
cacheComponent(component, code) {
|
|
172
178
|
if (this.compilationCache.size >= this.config.maxCacheSize) {
|
|
173
179
|
const firstKey = this.compilationCache.keys().next().value;
|
|
174
180
|
this.compilationCache.delete(firstKey);
|
|
175
181
|
}
|
|
176
|
-
this.
|
|
182
|
+
const cacheKey = this.createCacheKey(component.name, code);
|
|
183
|
+
this.compilationCache.set(cacheKey, component);
|
|
177
184
|
}
|
|
178
185
|
createCompilationError(error, componentName) {
|
|
179
186
|
return {
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ export { DEFAULT_PRESETS, DEFAULT_PLUGINS, PRODUCTION_CONFIG, DEVELOPMENT_CONFIG
|
|
|
7
7
|
export { ComponentRegistry } from './registry';
|
|
8
8
|
export { ComponentResolver, ComponentSpec, ResolvedComponents } from './registry';
|
|
9
9
|
export { createErrorBoundary, withErrorBoundary, formatComponentError, createErrorLogger } from './runtime';
|
|
10
|
-
export { wrapComponent, memoizeComponent, lazyComponent, injectProps, conditionalComponent, withErrorHandler, portalComponent, WrapperOptions } from './runtime';
|
|
11
10
|
export { buildComponentProps, normalizeCallbacks, normalizeStyles, validateComponentProps, mergeProps, createPropsTransformer, wrapCallbacksWithLogging, extractPropPaths, PropBuilderOptions } from './runtime';
|
|
12
11
|
export { ComponentHierarchyRegistrar, registerComponentHierarchy, validateComponentSpec, flattenComponentHierarchy, countComponentsInHierarchy, HierarchyRegistrationResult, ComponentRegistrationError, HierarchyRegistrationOptions } from './runtime';
|
|
13
12
|
export { ReactRootManager, reactRootManager, ManagedReactRoot } from './runtime';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAG/C,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EACL,eAAe,EACf,eAAe,E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,EAC1B,4BAA4B,EAC7B,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,WAAW,CAAC;AAGnB,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACL,WAAW,EACX,4BAA4B,EAC7B,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACpB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EACL,eAAe,EACf,eAAe,EACf,eAAe,EAChB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,YAAY,EACZ,UAAU,EACV,YAAY,EACb,MAAM,2BAA2B,CAAC;AAGnC,eAAO,MAAM,OAAO,WAAW,CAAC;AAGhC,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;CAiB3B,CAAC;AAQF,wBAAgB,kBAAkB,CAChC,aAAa,EAAE,GAAG,EAClB,MAAM,CAAC,EAAE;IACP,QAAQ,CAAC,EAAE,OAAO,CAAC,OAAO,SAAS,EAAE,cAAc,CAAC,CAAC;IACrD,QAAQ,CAAC,EAAE,OAAO,CAAC,OAAO,SAAS,EAAE,cAAc,CAAC,CAAC;CACtD;;;;;EAcF"}
|
package/dist/index.js
CHANGED
|
@@ -14,8 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.DEFAULT_CONFIGS = exports.VERSION = exports.CacheManager = exports.resourceManager = exports.ResourceManager = exports.ComponentErrorAnalyzer = exports.LibraryLoader = exports.createStandardLibraries = exports.StandardLibraryManager = exports.createDefaultComponentStyles = exports.SetupStyles = exports.createRuntimeUtilities = exports.RuntimeUtilities = exports.reactRootManager = exports.ReactRootManager = exports.countComponentsInHierarchy = exports.flattenComponentHierarchy = exports.validateComponentSpec = exports.registerComponentHierarchy = exports.ComponentHierarchyRegistrar = exports.extractPropPaths = exports.wrapCallbacksWithLogging = exports.createPropsTransformer = exports.mergeProps = exports.validateComponentProps = exports.normalizeStyles = exports.normalizeCallbacks = exports.buildComponentProps = exports.
|
|
18
|
-
exports.createReactRuntime = void 0;
|
|
17
|
+
exports.createReactRuntime = exports.DEFAULT_CONFIGS = exports.VERSION = exports.CacheManager = exports.resourceManager = exports.ResourceManager = exports.ComponentErrorAnalyzer = exports.LibraryLoader = exports.createStandardLibraries = exports.StandardLibraryManager = exports.createDefaultComponentStyles = exports.SetupStyles = exports.createRuntimeUtilities = exports.RuntimeUtilities = exports.reactRootManager = exports.ReactRootManager = exports.countComponentsInHierarchy = exports.flattenComponentHierarchy = exports.validateComponentSpec = exports.registerComponentHierarchy = exports.ComponentHierarchyRegistrar = exports.extractPropPaths = exports.wrapCallbacksWithLogging = exports.createPropsTransformer = exports.mergeProps = exports.validateComponentProps = exports.normalizeStyles = exports.normalizeCallbacks = exports.buildComponentProps = exports.createErrorLogger = exports.formatComponentError = exports.withErrorBoundary = exports.createErrorBoundary = exports.ComponentSpec = exports.ComponentResolver = exports.ComponentRegistry = exports.getJSXConfig = exports.validateBabelPresets = exports.getBabelConfig = exports.DEVELOPMENT_CONFIG = exports.PRODUCTION_CONFIG = exports.DEFAULT_PLUGINS = exports.DEFAULT_PRESETS = exports.ComponentCompiler = void 0;
|
|
19
18
|
const compiler_1 = require("./compiler");
|
|
20
19
|
const registry_1 = require("./registry");
|
|
21
20
|
const registry_2 = require("./registry");
|
|
@@ -41,31 +40,23 @@ Object.defineProperty(exports, "withErrorBoundary", { enumerable: true, get: fun
|
|
|
41
40
|
Object.defineProperty(exports, "formatComponentError", { enumerable: true, get: function () { return runtime_1.formatComponentError; } });
|
|
42
41
|
Object.defineProperty(exports, "createErrorLogger", { enumerable: true, get: function () { return runtime_1.createErrorLogger; } });
|
|
43
42
|
var runtime_2 = require("./runtime");
|
|
44
|
-
Object.defineProperty(exports, "
|
|
45
|
-
Object.defineProperty(exports, "
|
|
46
|
-
Object.defineProperty(exports, "
|
|
47
|
-
Object.defineProperty(exports, "
|
|
48
|
-
Object.defineProperty(exports, "
|
|
49
|
-
Object.defineProperty(exports, "
|
|
50
|
-
Object.defineProperty(exports, "
|
|
43
|
+
Object.defineProperty(exports, "buildComponentProps", { enumerable: true, get: function () { return runtime_2.buildComponentProps; } });
|
|
44
|
+
Object.defineProperty(exports, "normalizeCallbacks", { enumerable: true, get: function () { return runtime_2.normalizeCallbacks; } });
|
|
45
|
+
Object.defineProperty(exports, "normalizeStyles", { enumerable: true, get: function () { return runtime_2.normalizeStyles; } });
|
|
46
|
+
Object.defineProperty(exports, "validateComponentProps", { enumerable: true, get: function () { return runtime_2.validateComponentProps; } });
|
|
47
|
+
Object.defineProperty(exports, "mergeProps", { enumerable: true, get: function () { return runtime_2.mergeProps; } });
|
|
48
|
+
Object.defineProperty(exports, "createPropsTransformer", { enumerable: true, get: function () { return runtime_2.createPropsTransformer; } });
|
|
49
|
+
Object.defineProperty(exports, "wrapCallbacksWithLogging", { enumerable: true, get: function () { return runtime_2.wrapCallbacksWithLogging; } });
|
|
50
|
+
Object.defineProperty(exports, "extractPropPaths", { enumerable: true, get: function () { return runtime_2.extractPropPaths; } });
|
|
51
51
|
var runtime_3 = require("./runtime");
|
|
52
|
-
Object.defineProperty(exports, "
|
|
53
|
-
Object.defineProperty(exports, "
|
|
54
|
-
Object.defineProperty(exports, "
|
|
55
|
-
Object.defineProperty(exports, "
|
|
56
|
-
Object.defineProperty(exports, "
|
|
57
|
-
Object.defineProperty(exports, "createPropsTransformer", { enumerable: true, get: function () { return runtime_3.createPropsTransformer; } });
|
|
58
|
-
Object.defineProperty(exports, "wrapCallbacksWithLogging", { enumerable: true, get: function () { return runtime_3.wrapCallbacksWithLogging; } });
|
|
59
|
-
Object.defineProperty(exports, "extractPropPaths", { enumerable: true, get: function () { return runtime_3.extractPropPaths; } });
|
|
52
|
+
Object.defineProperty(exports, "ComponentHierarchyRegistrar", { enumerable: true, get: function () { return runtime_3.ComponentHierarchyRegistrar; } });
|
|
53
|
+
Object.defineProperty(exports, "registerComponentHierarchy", { enumerable: true, get: function () { return runtime_3.registerComponentHierarchy; } });
|
|
54
|
+
Object.defineProperty(exports, "validateComponentSpec", { enumerable: true, get: function () { return runtime_3.validateComponentSpec; } });
|
|
55
|
+
Object.defineProperty(exports, "flattenComponentHierarchy", { enumerable: true, get: function () { return runtime_3.flattenComponentHierarchy; } });
|
|
56
|
+
Object.defineProperty(exports, "countComponentsInHierarchy", { enumerable: true, get: function () { return runtime_3.countComponentsInHierarchy; } });
|
|
60
57
|
var runtime_4 = require("./runtime");
|
|
61
|
-
Object.defineProperty(exports, "
|
|
62
|
-
Object.defineProperty(exports, "
|
|
63
|
-
Object.defineProperty(exports, "validateComponentSpec", { enumerable: true, get: function () { return runtime_4.validateComponentSpec; } });
|
|
64
|
-
Object.defineProperty(exports, "flattenComponentHierarchy", { enumerable: true, get: function () { return runtime_4.flattenComponentHierarchy; } });
|
|
65
|
-
Object.defineProperty(exports, "countComponentsInHierarchy", { enumerable: true, get: function () { return runtime_4.countComponentsInHierarchy; } });
|
|
66
|
-
var runtime_5 = require("./runtime");
|
|
67
|
-
Object.defineProperty(exports, "ReactRootManager", { enumerable: true, get: function () { return runtime_5.ReactRootManager; } });
|
|
68
|
-
Object.defineProperty(exports, "reactRootManager", { enumerable: true, get: function () { return runtime_5.reactRootManager; } });
|
|
58
|
+
Object.defineProperty(exports, "ReactRootManager", { enumerable: true, get: function () { return runtime_4.ReactRootManager; } });
|
|
59
|
+
Object.defineProperty(exports, "reactRootManager", { enumerable: true, get: function () { return runtime_4.reactRootManager; } });
|
|
69
60
|
var runtime_utilities_1 = require("./utilities/runtime-utilities");
|
|
70
61
|
Object.defineProperty(exports, "RuntimeUtilities", { enumerable: true, get: function () { return runtime_utilities_1.RuntimeUtilities; } });
|
|
71
62
|
Object.defineProperty(exports, "createRuntimeUtilities", { enumerable: true, get: function () { return runtime_utilities_1.createRuntimeUtilities; } });
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { createErrorBoundary, withErrorBoundary, formatComponentError, createErrorLogger } from './error-boundary';
|
|
2
|
-
export { wrapComponent, memoizeComponent, lazyComponent, injectProps, conditionalComponent, withErrorHandler, portalComponent, WrapperOptions } from './component-wrapper';
|
|
3
2
|
export { buildComponentProps, normalizeCallbacks, normalizeStyles, validateComponentProps, mergeProps, createPropsTransformer, wrapCallbacksWithLogging, extractPropPaths, PropBuilderOptions } from './prop-builder';
|
|
4
3
|
export { ComponentHierarchyRegistrar, registerComponentHierarchy, validateComponentSpec, flattenComponentHierarchy, countComponentsInHierarchy, HierarchyRegistrationResult, ComponentRegistrationError, HierarchyRegistrationOptions } from './component-hierarchy';
|
|
5
4
|
export { ReactRootManager, reactRootManager, ManagedReactRoot } from './react-root-manager';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EAClB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EAClB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,sBAAsB,EACtB,UAAU,EACV,sBAAsB,EACtB,wBAAwB,EACxB,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,2BAA2B,EAC3B,0BAA0B,EAC1B,qBAAqB,EACrB,yBAAyB,EACzB,0BAA0B,EAC1B,2BAA2B,EAC3B,0BAA0B,EAC1B,4BAA4B,EAC7B,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,sBAAsB,CAAC"}
|
package/dist/runtime/index.js
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.reactRootManager = exports.ReactRootManager = exports.countComponentsInHierarchy = exports.flattenComponentHierarchy = exports.validateComponentSpec = exports.registerComponentHierarchy = exports.ComponentHierarchyRegistrar = exports.extractPropPaths = exports.wrapCallbacksWithLogging = exports.createPropsTransformer = exports.mergeProps = exports.validateComponentProps = exports.normalizeStyles = exports.normalizeCallbacks = exports.buildComponentProps = exports.
|
|
3
|
+
exports.reactRootManager = exports.ReactRootManager = exports.countComponentsInHierarchy = exports.flattenComponentHierarchy = exports.validateComponentSpec = exports.registerComponentHierarchy = exports.ComponentHierarchyRegistrar = exports.extractPropPaths = exports.wrapCallbacksWithLogging = exports.createPropsTransformer = exports.mergeProps = exports.validateComponentProps = exports.normalizeStyles = exports.normalizeCallbacks = exports.buildComponentProps = exports.createErrorLogger = exports.formatComponentError = exports.withErrorBoundary = exports.createErrorBoundary = void 0;
|
|
4
4
|
var error_boundary_1 = require("./error-boundary");
|
|
5
5
|
Object.defineProperty(exports, "createErrorBoundary", { enumerable: true, get: function () { return error_boundary_1.createErrorBoundary; } });
|
|
6
6
|
Object.defineProperty(exports, "withErrorBoundary", { enumerable: true, get: function () { return error_boundary_1.withErrorBoundary; } });
|
|
7
7
|
Object.defineProperty(exports, "formatComponentError", { enumerable: true, get: function () { return error_boundary_1.formatComponentError; } });
|
|
8
8
|
Object.defineProperty(exports, "createErrorLogger", { enumerable: true, get: function () { return error_boundary_1.createErrorLogger; } });
|
|
9
|
-
var component_wrapper_1 = require("./component-wrapper");
|
|
10
|
-
Object.defineProperty(exports, "wrapComponent", { enumerable: true, get: function () { return component_wrapper_1.wrapComponent; } });
|
|
11
|
-
Object.defineProperty(exports, "memoizeComponent", { enumerable: true, get: function () { return component_wrapper_1.memoizeComponent; } });
|
|
12
|
-
Object.defineProperty(exports, "lazyComponent", { enumerable: true, get: function () { return component_wrapper_1.lazyComponent; } });
|
|
13
|
-
Object.defineProperty(exports, "injectProps", { enumerable: true, get: function () { return component_wrapper_1.injectProps; } });
|
|
14
|
-
Object.defineProperty(exports, "conditionalComponent", { enumerable: true, get: function () { return component_wrapper_1.conditionalComponent; } });
|
|
15
|
-
Object.defineProperty(exports, "withErrorHandler", { enumerable: true, get: function () { return component_wrapper_1.withErrorHandler; } });
|
|
16
|
-
Object.defineProperty(exports, "portalComponent", { enumerable: true, get: function () { return component_wrapper_1.portalComponent; } });
|
|
17
9
|
var prop_builder_1 = require("./prop-builder");
|
|
18
10
|
Object.defineProperty(exports, "buildComponentProps", { enumerable: true, get: function () { return prop_builder_1.buildComponentProps; } });
|
|
19
11
|
Object.defineProperty(exports, "normalizeCallbacks", { enumerable: true, get: function () { return prop_builder_1.normalizeCallbacks; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-root-manager.d.ts","sourceRoot":"","sources":["../../src/runtime/react-root-manager.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,GAAG,CAAC;IACV,SAAS,EAAE,WAAW,CAAC;IACvB,WAAW,EAAE,OAAO,CAAC;IACrB,cAAc,CAAC,EAAE,IAAI,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAMD,qBAAa,gBAAgB;IAC3B,O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OAAO,CAAC,IAAI,CAAC;IAiB/D,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAOpC,QAAQ,IAAI;QACV,UAAU,EAAE,MAAM,CAAC;QACnB,cAAc,EAAE,MAAM,CAAC;QACvB,eAAe,EAAE,MAAM,CAAC;KACzB;IAWK,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAI/B;AAGD,eAAO,MAAM,gBAAgB,kBAAyB,CAAC"}
|
|
@@ -72,8 +72,7 @@ class ReactRootManager {
|
|
|
72
72
|
this.renderingRoots.delete(rootId);
|
|
73
73
|
if (managedRoot.container) {
|
|
74
74
|
delete managedRoot.container._reactRootContainer;
|
|
75
|
-
|
|
76
|
-
managedRoot.container.parentNode?.replaceChild(newContainer, managedRoot.container);
|
|
75
|
+
managedRoot.container.innerHTML = '';
|
|
77
76
|
}
|
|
78
77
|
resolve();
|
|
79
78
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export type TimerId = number | NodeJS.Timeout;
|
|
1
3
|
export interface ManagedResource {
|
|
2
4
|
type: 'timer' | 'interval' | 'animationFrame' | 'eventListener' | 'domElement' | 'observable' | 'reactRoot';
|
|
3
|
-
id: string |
|
|
5
|
+
id: string | TimerId;
|
|
4
6
|
cleanup: () => void;
|
|
5
7
|
metadata?: Record<string, any>;
|
|
6
8
|
}
|
|
@@ -10,12 +12,12 @@ export declare class ResourceManager {
|
|
|
10
12
|
private cleanupCallbacks;
|
|
11
13
|
setTimeout(componentId: string, callback: () => void, delay: number, metadata?: Record<string, any>): number;
|
|
12
14
|
setInterval(componentId: string, callback: () => void, delay: number, metadata?: Record<string, any>): number;
|
|
13
|
-
requestAnimationFrame(componentId: string, callback: FrameRequestCallback, metadata?: Record<string, any>):
|
|
15
|
+
requestAnimationFrame(componentId: string, callback: FrameRequestCallback, metadata?: Record<string, any>): TimerId;
|
|
14
16
|
clearTimeout(componentId: string, id: number): void;
|
|
15
17
|
clearInterval(componentId: string, id: number): void;
|
|
16
|
-
cancelAnimationFrame(componentId: string, id:
|
|
18
|
+
cancelAnimationFrame(componentId: string, id: TimerId): void;
|
|
17
19
|
addEventListener(componentId: string, target: EventTarget, type: string, listener: EventListener, options?: AddEventListenerOptions): void;
|
|
18
|
-
registerDOMElement(componentId: string, element:
|
|
20
|
+
registerDOMElement(componentId: string, element: any, cleanup?: () => void): void;
|
|
19
21
|
registerReactRoot(componentId: string, root: any, unmountFn: () => void): void;
|
|
20
22
|
registerCleanup(componentId: string, cleanup: () => void): void;
|
|
21
23
|
registerGlobalResource(resource: ManagedResource): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-manager.d.ts","sourceRoot":"","sources":["../../src/utilities/resource-manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resource-manager.d.ts","sourceRoot":"","sources":["../../src/utilities/resource-manager.ts"],"names":[],"mappings":";AAOA,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC;AAE9C,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,OAAO,GAAG,UAAU,GAAG,gBAAgB,GAAG,eAAe,GAAG,YAAY,GAAG,YAAY,GAAG,WAAW,CAAC;IAC5G,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IACrB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AAiDD,qBAAa,eAAe;IAC1B,OAAO,CAAC,SAAS,CAA2C;IAC5D,OAAO,CAAC,eAAe,CAA8B;IACrD,OAAO,CAAC,gBAAgB,CAAqC;IAK7D,UAAU,CACR,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,IAAI,EACpB,KAAK,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC7B,MAAM;IAmBT,WAAW,CACT,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AAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACvC,mBAAmB,EAAE,MAAM,CAAC;KAC7B;CAeF;AAGD,eAAO,MAAM,eAAe,iBAAwB,CAAC"}
|
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resourceManager = exports.ResourceManager = void 0;
|
|
4
|
+
const getTimerFunctions = () => {
|
|
5
|
+
if (typeof window !== 'undefined' && window.setTimeout) {
|
|
6
|
+
return {
|
|
7
|
+
setTimeout: window.setTimeout.bind(window),
|
|
8
|
+
clearTimeout: window.clearTimeout.bind(window),
|
|
9
|
+
setInterval: window.setInterval.bind(window),
|
|
10
|
+
clearInterval: window.clearInterval.bind(window),
|
|
11
|
+
requestAnimationFrame: window.requestAnimationFrame?.bind(window),
|
|
12
|
+
cancelAnimationFrame: window.cancelAnimationFrame?.bind(window)
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
else if (typeof global !== 'undefined' && global.setTimeout) {
|
|
16
|
+
return {
|
|
17
|
+
setTimeout: global.setTimeout,
|
|
18
|
+
clearTimeout: global.clearTimeout,
|
|
19
|
+
setInterval: global.setInterval,
|
|
20
|
+
clearInterval: global.clearInterval,
|
|
21
|
+
requestAnimationFrame: undefined,
|
|
22
|
+
cancelAnimationFrame: undefined
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
const noop = () => { };
|
|
27
|
+
const noopWithReturn = () => 0;
|
|
28
|
+
return {
|
|
29
|
+
setTimeout: noopWithReturn,
|
|
30
|
+
clearTimeout: noop,
|
|
31
|
+
setInterval: noopWithReturn,
|
|
32
|
+
clearInterval: noop,
|
|
33
|
+
requestAnimationFrame: undefined,
|
|
34
|
+
cancelAnimationFrame: undefined
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const timers = getTimerFunctions();
|
|
4
39
|
class ResourceManager {
|
|
5
40
|
constructor() {
|
|
6
41
|
this.resources = new Map();
|
|
@@ -8,78 +43,94 @@ class ResourceManager {
|
|
|
8
43
|
this.cleanupCallbacks = new Map();
|
|
9
44
|
}
|
|
10
45
|
setTimeout(componentId, callback, delay, metadata) {
|
|
11
|
-
const id =
|
|
46
|
+
const id = timers.setTimeout(() => {
|
|
12
47
|
this.removeResource(componentId, 'timer', id);
|
|
13
48
|
callback();
|
|
14
49
|
}, delay);
|
|
15
50
|
this.addResource(componentId, {
|
|
16
51
|
type: 'timer',
|
|
17
52
|
id,
|
|
18
|
-
cleanup: () =>
|
|
53
|
+
cleanup: () => timers.clearTimeout(id),
|
|
19
54
|
metadata
|
|
20
55
|
});
|
|
21
56
|
return id;
|
|
22
57
|
}
|
|
23
58
|
setInterval(componentId, callback, delay, metadata) {
|
|
24
|
-
const id =
|
|
59
|
+
const id = timers.setInterval(callback, delay);
|
|
25
60
|
this.addResource(componentId, {
|
|
26
61
|
type: 'interval',
|
|
27
62
|
id,
|
|
28
|
-
cleanup: () =>
|
|
63
|
+
cleanup: () => timers.clearInterval(id),
|
|
29
64
|
metadata
|
|
30
65
|
});
|
|
31
66
|
return id;
|
|
32
67
|
}
|
|
33
68
|
requestAnimationFrame(componentId, callback, metadata) {
|
|
34
|
-
|
|
69
|
+
if (!timers.requestAnimationFrame) {
|
|
70
|
+
return this.setTimeout(componentId, () => callback(Date.now()), 16, metadata);
|
|
71
|
+
}
|
|
72
|
+
const id = timers.requestAnimationFrame((time) => {
|
|
35
73
|
this.removeResource(componentId, 'animationFrame', id);
|
|
36
74
|
callback(time);
|
|
37
75
|
});
|
|
38
76
|
this.addResource(componentId, {
|
|
39
77
|
type: 'animationFrame',
|
|
40
78
|
id,
|
|
41
|
-
cleanup: () =>
|
|
79
|
+
cleanup: () => timers.cancelAnimationFrame?.(id),
|
|
42
80
|
metadata
|
|
43
81
|
});
|
|
44
82
|
return id;
|
|
45
83
|
}
|
|
46
84
|
clearTimeout(componentId, id) {
|
|
47
|
-
|
|
85
|
+
timers.clearTimeout(id);
|
|
48
86
|
this.removeResource(componentId, 'timer', id);
|
|
49
87
|
}
|
|
50
88
|
clearInterval(componentId, id) {
|
|
51
|
-
|
|
89
|
+
timers.clearInterval(id);
|
|
52
90
|
this.removeResource(componentId, 'interval', id);
|
|
53
91
|
}
|
|
54
92
|
cancelAnimationFrame(componentId, id) {
|
|
55
|
-
|
|
93
|
+
if (timers.cancelAnimationFrame) {
|
|
94
|
+
timers.cancelAnimationFrame(id);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
timers.clearTimeout(id);
|
|
98
|
+
}
|
|
56
99
|
this.removeResource(componentId, 'animationFrame', id);
|
|
57
100
|
}
|
|
58
101
|
addEventListener(componentId, target, type, listener, options) {
|
|
59
|
-
target.addEventListener
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
102
|
+
if (target && typeof target.addEventListener === 'function') {
|
|
103
|
+
target.addEventListener(type, listener, options);
|
|
104
|
+
const resourceId = `${type}-${Date.now()}-${Math.random()}`;
|
|
105
|
+
this.addResource(componentId, {
|
|
106
|
+
type: 'eventListener',
|
|
107
|
+
id: resourceId,
|
|
108
|
+
cleanup: () => {
|
|
109
|
+
if (target && typeof target.removeEventListener === 'function') {
|
|
110
|
+
target.removeEventListener(type, listener, options);
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
metadata: { target, type, options }
|
|
114
|
+
});
|
|
115
|
+
}
|
|
67
116
|
}
|
|
68
117
|
registerDOMElement(componentId, element, cleanup) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
cleanup
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
element.parentNode.removeChild
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
118
|
+
if (typeof document !== 'undefined' && element && element.parentNode) {
|
|
119
|
+
const resourceId = `dom-${Date.now()}-${Math.random()}`;
|
|
120
|
+
this.addResource(componentId, {
|
|
121
|
+
type: 'domElement',
|
|
122
|
+
id: resourceId,
|
|
123
|
+
cleanup: () => {
|
|
124
|
+
if (cleanup) {
|
|
125
|
+
cleanup();
|
|
126
|
+
}
|
|
127
|
+
if (element && element.parentNode && typeof element.parentNode.removeChild === 'function') {
|
|
128
|
+
element.parentNode.removeChild(element);
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
metadata: { element }
|
|
132
|
+
});
|
|
133
|
+
}
|
|
83
134
|
}
|
|
84
135
|
registerReactRoot(componentId, root, unmountFn) {
|
|
85
136
|
this.addResource(componentId, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/react-runtime",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.79.0",
|
|
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
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://github.com/MemberJunction/MJ#readme",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@memberjunction/core": "2.
|
|
29
|
-
"@memberjunction/global": "2.
|
|
30
|
-
"@memberjunction/interactive-component-types": "2.
|
|
28
|
+
"@memberjunction/core": "2.79.0",
|
|
29
|
+
"@memberjunction/global": "2.79.0",
|
|
30
|
+
"@memberjunction/interactive-component-types": "2.79.0",
|
|
31
31
|
"@babel/standalone": "^7.23.5",
|
|
32
32
|
"rxjs": "^7.8.1"
|
|
33
33
|
},
|
|
@@ -34,6 +34,7 @@ const DEFAULT_COMPILER_CONFIG: CompilerConfig = {
|
|
|
34
34
|
export class ComponentCompiler {
|
|
35
35
|
private config: CompilerConfig;
|
|
36
36
|
private compilationCache: Map<string, CompiledComponent>;
|
|
37
|
+
private cacheAccessOrder: string[]; // Track access order for LRU
|
|
37
38
|
private babelInstance: any;
|
|
38
39
|
|
|
39
40
|
/**
|
|
@@ -64,7 +65,7 @@ export class ComponentCompiler {
|
|
|
64
65
|
try {
|
|
65
66
|
// Check cache first if enabled
|
|
66
67
|
if (this.config.cache) {
|
|
67
|
-
const cached = this.getCachedComponent(options.componentName);
|
|
68
|
+
const cached = this.getCachedComponent(options.componentName, options.componentCode);
|
|
68
69
|
if (cached) {
|
|
69
70
|
return {
|
|
70
71
|
success: true,
|
|
@@ -101,7 +102,7 @@ export class ComponentCompiler {
|
|
|
101
102
|
|
|
102
103
|
// Cache if enabled
|
|
103
104
|
if (this.config.cache) {
|
|
104
|
-
this.cacheComponent(compiledComponent);
|
|
105
|
+
this.cacheComponent(compiledComponent, options.componentCode);
|
|
105
106
|
}
|
|
106
107
|
|
|
107
108
|
return {
|
|
@@ -227,7 +228,7 @@ export class ComponentCompiler {
|
|
|
227
228
|
);
|
|
228
229
|
|
|
229
230
|
// Call createComponent to get the actual component
|
|
230
|
-
|
|
231
|
+
const Component = createComponentFn(
|
|
231
232
|
React,
|
|
232
233
|
ReactDOM,
|
|
233
234
|
React.useState,
|
|
@@ -242,6 +243,9 @@ export class ComponentCompiler {
|
|
|
242
243
|
styles,
|
|
243
244
|
console
|
|
244
245
|
);
|
|
246
|
+
|
|
247
|
+
// Return the component directly
|
|
248
|
+
return Component;
|
|
245
249
|
};
|
|
246
250
|
} catch (error: any) {
|
|
247
251
|
throw new Error(`Failed to create component factory: ${error.message}`);
|
|
@@ -326,24 +330,38 @@ export class ComponentCompiler {
|
|
|
326
330
|
/**
|
|
327
331
|
* Gets a cached component if available
|
|
328
332
|
* @param componentName - Name of the component
|
|
333
|
+
* @param code - Component source code
|
|
329
334
|
* @returns Cached component or undefined
|
|
330
335
|
*/
|
|
331
|
-
private getCachedComponent(componentName: string): CompiledComponent | undefined {
|
|
332
|
-
//
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
336
|
+
private getCachedComponent(componentName: string, code: string): CompiledComponent | undefined {
|
|
337
|
+
// Create cache key based on name AND content hash
|
|
338
|
+
const cacheKey = this.createCacheKey(componentName, code);
|
|
339
|
+
return this.compilationCache.get(cacheKey);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Creates a cache key based on component name and code content
|
|
344
|
+
* @param componentName - Name of the component
|
|
345
|
+
* @param code - Component source code
|
|
346
|
+
* @returns Cache key
|
|
347
|
+
*/
|
|
348
|
+
private createCacheKey(componentName: string, code: string): string {
|
|
349
|
+
// Simple hash function for code content
|
|
350
|
+
let hash = 0;
|
|
351
|
+
for (let i = 0; i < code.length; i++) {
|
|
352
|
+
const char = code.charCodeAt(i);
|
|
353
|
+
hash = ((hash << 5) - hash) + char;
|
|
354
|
+
hash = hash & hash; // Convert to 32-bit integer
|
|
338
355
|
}
|
|
339
|
-
return
|
|
356
|
+
return `${componentName}_${hash.toString(36)}`;
|
|
340
357
|
}
|
|
341
358
|
|
|
342
359
|
/**
|
|
343
360
|
* Caches a compiled component
|
|
344
361
|
* @param component - Component to cache
|
|
362
|
+
* @param code - Original source code
|
|
345
363
|
*/
|
|
346
|
-
private cacheComponent(component: CompiledComponent): void {
|
|
364
|
+
private cacheComponent(component: CompiledComponent, code: string): void {
|
|
347
365
|
// Enforce cache size limit
|
|
348
366
|
if (this.compilationCache.size >= this.config.maxCacheSize) {
|
|
349
367
|
// Remove oldest entry (first in map)
|
|
@@ -351,7 +369,8 @@ export class ComponentCompiler {
|
|
|
351
369
|
this.compilationCache.delete(firstKey);
|
|
352
370
|
}
|
|
353
371
|
|
|
354
|
-
this.
|
|
372
|
+
const cacheKey = this.createCacheKey(component.name, code);
|
|
373
|
+
this.compilationCache.set(cacheKey, component);
|
|
355
374
|
}
|
|
356
375
|
|
|
357
376
|
/**
|
package/src/index.ts
CHANGED
|
@@ -40,16 +40,6 @@ export {
|
|
|
40
40
|
createErrorLogger
|
|
41
41
|
} from './runtime';
|
|
42
42
|
|
|
43
|
-
export {
|
|
44
|
-
wrapComponent,
|
|
45
|
-
memoizeComponent,
|
|
46
|
-
lazyComponent,
|
|
47
|
-
injectProps,
|
|
48
|
-
conditionalComponent,
|
|
49
|
-
withErrorHandler,
|
|
50
|
-
portalComponent,
|
|
51
|
-
WrapperOptions
|
|
52
|
-
} from './runtime';
|
|
53
43
|
|
|
54
44
|
export {
|
|
55
45
|
buildComponentProps,
|
package/src/runtime/index.ts
CHANGED
|
@@ -10,16 +10,6 @@ export {
|
|
|
10
10
|
createErrorLogger
|
|
11
11
|
} from './error-boundary';
|
|
12
12
|
|
|
13
|
-
export {
|
|
14
|
-
wrapComponent,
|
|
15
|
-
memoizeComponent,
|
|
16
|
-
lazyComponent,
|
|
17
|
-
injectProps,
|
|
18
|
-
conditionalComponent,
|
|
19
|
-
withErrorHandler,
|
|
20
|
-
portalComponent,
|
|
21
|
-
WrapperOptions
|
|
22
|
-
} from './component-wrapper';
|
|
23
13
|
|
|
24
14
|
export {
|
|
25
15
|
buildComponentProps,
|