slicejs-web-framework 3.1.0 → 3.1.1
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/Slice/Slice.js
CHANGED
|
@@ -132,24 +132,25 @@ export default class Slice {
|
|
|
132
132
|
|
|
133
133
|
let isVisual = slice.paths.components[componentCategory].type === 'Visual';
|
|
134
134
|
let modulePath = `${slice.paths.components[componentCategory].path}/${componentName}/${componentName}.js`;
|
|
135
|
+
const isJsOnlyVisualComponent = isVisual && (componentName === 'MultiRoute' || componentName === 'Route' || componentName === 'Link');
|
|
135
136
|
|
|
136
137
|
// Load template, class, and CSS concurrently if needed
|
|
137
138
|
try {
|
|
138
139
|
// 📦 Skip individual loading if component is available from bundles
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
140
|
+
const loadTemplate =
|
|
141
|
+
isFromBundle || !isVisual || isJsOnlyVisualComponent || this.controller.templates.has(componentName)
|
|
142
|
+
? Promise.resolve(null)
|
|
143
|
+
: this.controller.fetchText(componentName, 'html', componentCategory);
|
|
143
144
|
|
|
144
145
|
const loadClass =
|
|
145
146
|
isFromBundle || this.controller.classes.has(componentName)
|
|
146
147
|
? Promise.resolve(null)
|
|
147
148
|
: this.getClass(modulePath);
|
|
148
149
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
150
|
+
const loadCSS =
|
|
151
|
+
isFromBundle || !isVisual || isJsOnlyVisualComponent || this.controller.requestedStyles.has(componentName)
|
|
152
|
+
? Promise.resolve(null)
|
|
153
|
+
: this.controller.fetchText(componentName, 'css', componentCategory);
|
|
153
154
|
|
|
154
155
|
const [html, ComponentClass, css] = await Promise.all([loadTemplate, loadClass, loadCSS]);
|
|
155
156
|
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
|
|
4
|
+
globalThis.alert = () => {};
|
|
5
|
+
|
|
6
|
+
const { default: Slice } = await import('../Slice.js');
|
|
7
|
+
|
|
8
|
+
class FakeController {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.componentCategories = new Map([
|
|
11
|
+
['MultiRoute', 'Visual'],
|
|
12
|
+
['Route', 'Visual'],
|
|
13
|
+
['Link', 'Visual'],
|
|
14
|
+
['Button', 'Visual']
|
|
15
|
+
]);
|
|
16
|
+
this.templates = new Map();
|
|
17
|
+
this.classes = new Map();
|
|
18
|
+
this.requestedStyles = new Set();
|
|
19
|
+
this.loadedBundles = new Set();
|
|
20
|
+
this.activeComponents = new Map();
|
|
21
|
+
this.fetchCalls = 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
getBundleForComponent() {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
isComponentFromBundle() {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async fetchText() {
|
|
33
|
+
this.fetchCalls += 1;
|
|
34
|
+
throw new Error('fetchText should not be called for js-only visual components');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
verifyComponentIds() {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
registerComponent() {}
|
|
42
|
+
|
|
43
|
+
registerComponentsRecursively() {}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
class FakeStylesManager {
|
|
47
|
+
registerComponentStyles() {}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function createSlice() {
|
|
51
|
+
const instance = new Slice(
|
|
52
|
+
{
|
|
53
|
+
paths: {
|
|
54
|
+
components: {
|
|
55
|
+
Visual: {
|
|
56
|
+
path: '/Components/Visual',
|
|
57
|
+
type: 'Visual'
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
themeManager: {},
|
|
62
|
+
stylesManager: {},
|
|
63
|
+
logger: {},
|
|
64
|
+
debugger: { enabled: false },
|
|
65
|
+
loading: {},
|
|
66
|
+
events: {}
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
Controller: FakeController,
|
|
70
|
+
StylesManager: FakeStylesManager
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
instance.logger = {
|
|
75
|
+
logError() {},
|
|
76
|
+
logWarning() {},
|
|
77
|
+
logInfo() {}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
return instance;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
test('build does not fetch html/css for MultiRoute, Route, and Link', async () => {
|
|
84
|
+
const originalSlice = globalThis.slice;
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
const sliceInstance = createSlice();
|
|
88
|
+
globalThis.slice = sliceInstance;
|
|
89
|
+
|
|
90
|
+
class MultiRouteComponent {
|
|
91
|
+
constructor(props) {
|
|
92
|
+
this.props = props;
|
|
93
|
+
this.sliceId = 'MultiRoute';
|
|
94
|
+
}
|
|
95
|
+
async init() {}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
class RouteComponent {
|
|
99
|
+
constructor(props) {
|
|
100
|
+
this.props = props;
|
|
101
|
+
this.sliceId = 'Route';
|
|
102
|
+
}
|
|
103
|
+
async init() {}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
class LinkComponent {
|
|
107
|
+
constructor(props) {
|
|
108
|
+
this.props = props;
|
|
109
|
+
this.sliceId = 'Link';
|
|
110
|
+
}
|
|
111
|
+
async init() {}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
sliceInstance.controller.classes.set('MultiRoute', MultiRouteComponent);
|
|
115
|
+
sliceInstance.controller.classes.set('Route', RouteComponent);
|
|
116
|
+
sliceInstance.controller.classes.set('Link', LinkComponent);
|
|
117
|
+
|
|
118
|
+
const builtMultiRoute = await sliceInstance.build('MultiRoute', {});
|
|
119
|
+
const builtRoute = await sliceInstance.build('Route', {});
|
|
120
|
+
const builtLink = await sliceInstance.build('Link', {});
|
|
121
|
+
|
|
122
|
+
assert.ok(builtMultiRoute, 'Expected MultiRoute instance to be created');
|
|
123
|
+
assert.ok(builtRoute, 'Expected Route instance to be created');
|
|
124
|
+
assert.ok(builtLink, 'Expected Link instance to be created');
|
|
125
|
+
assert.equal(sliceInstance.controller.fetchCalls, 0);
|
|
126
|
+
} finally {
|
|
127
|
+
globalThis.slice = originalSlice;
|
|
128
|
+
}
|
|
129
|
+
});
|