native-document 1.0.281 → 1.0.283
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/devtools/ComponentRegistry.js +15 -2
- package/devtools/nd-vite-devtools.js +3 -3
- package/devtools/src/templates/hrm.hook.template.js +45 -25
- package/devtools/src/transformers/transformForHrm.js +29 -4
- package/package.json +1 -1
- package/src/core/data/Observable.hrm.js +4 -4
- package/src/core/data/ObservableQuery.js +7 -0
|
@@ -85,7 +85,9 @@ const ComponentRegistry = (function() {
|
|
|
85
85
|
version: 0,
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
|
-
|
|
88
|
+
const factoryWrapper = wrapper(id, factory, metadata, registry.get(id));
|
|
89
|
+
factoryWrapper.originalFactory = factory;
|
|
90
|
+
return factoryWrapper;
|
|
89
91
|
},
|
|
90
92
|
update(id, newFactory, globalId) {
|
|
91
93
|
const component = registry.get(id);
|
|
@@ -99,6 +101,9 @@ const ComponentRegistry = (function() {
|
|
|
99
101
|
DebugManager.log('[HMR] Updating factory is not a function : ', newFactory);
|
|
100
102
|
return;
|
|
101
103
|
}
|
|
104
|
+
if(oldFactory.originalFactory?.toString() === newFactory.originalFactory?.toString()) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
102
107
|
component.factory = newFactory;
|
|
103
108
|
component.version++;
|
|
104
109
|
const instances = Array.from(component.instances);
|
|
@@ -125,7 +130,15 @@ const ComponentRegistry = (function() {
|
|
|
125
130
|
}
|
|
126
131
|
timers.push({ timerId, cleaner });
|
|
127
132
|
},
|
|
128
|
-
cleanTimer(id) {
|
|
133
|
+
cleanTimer(id, newFactory) {
|
|
134
|
+
const component = registry.get(id);
|
|
135
|
+
if(!component) {
|
|
136
|
+
DebugManager.warn(`[HMR] Component ${id} not found`);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if(component.factory.originalFactory?.toString() === newFactory.originalFactory?.toString()) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
129
142
|
const timers = timerRegistry.get(id);
|
|
130
143
|
if (!timers) {
|
|
131
144
|
return;
|
|
@@ -6,8 +6,8 @@ import transformNdForHrm from './src/transformers/transformNdForHrm.js';
|
|
|
6
6
|
|
|
7
7
|
export default function NdViteDevtools(options) {
|
|
8
8
|
const {
|
|
9
|
-
include =
|
|
10
|
-
|
|
9
|
+
include = /\.js$/,
|
|
10
|
+
includeNdFile = /\.nd\.js$/,
|
|
11
11
|
preserveState = true,
|
|
12
12
|
} = options;
|
|
13
13
|
|
|
@@ -49,7 +49,7 @@ export default function NdViteDevtools(options) {
|
|
|
49
49
|
return null;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
if (
|
|
52
|
+
if (includeNdFile.test(id)) {
|
|
53
53
|
try {
|
|
54
54
|
return transformNdForHrm(code, id, { preserveState, ...options });
|
|
55
55
|
} catch (error) {
|
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
|
|
2
2
|
if (import.meta.hot) {
|
|
3
3
|
const componentIds = ${componentIds};
|
|
4
|
+
|
|
5
|
+
const cleanTimers = (newModule) => {
|
|
6
|
+
console.log('[HMR Browser] Calling ComponentRegistry.update()');
|
|
7
|
+
try {
|
|
8
|
+
let defaultId = '${id}';
|
|
9
|
+
for(const component of componentIds) {
|
|
10
|
+
if(newModule[component.name]) {
|
|
11
|
+
ComponentRegistry.cleanTimer(component.id, newModule[component.name]);
|
|
12
|
+
}
|
|
13
|
+
if(component.isDefault) {
|
|
14
|
+
defaultId = component.id;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if(newModule.default) {
|
|
18
|
+
ComponentRegistry.cleanTimer(defaultId, newModule.default)
|
|
19
|
+
}
|
|
20
|
+
console.log('[HMR Browser] ✓ Clean timer successful');
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.error('[HMR Browser] ✗ Clean timers failed:', error);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
const updateComponents = (newModule) => {
|
|
28
|
+
try {
|
|
29
|
+
let defaultId = '${id}';
|
|
30
|
+
for(const component of componentIds) {
|
|
31
|
+
if(newModule[component.name]) {
|
|
32
|
+
ComponentRegistry.update(component.id, newModule[component.name], '${id}');
|
|
33
|
+
}
|
|
34
|
+
if(component.isDefault) {
|
|
35
|
+
defaultId = component.id;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if(newModule.default) {
|
|
39
|
+
ComponentRegistry.update(defaultId, newModule.default, '${id}');
|
|
40
|
+
}
|
|
41
|
+
// console.log('[HMR Browser] ✓ Update successful');
|
|
42
|
+
} catch (error) {
|
|
43
|
+
console.error('[HMR Browser] ✗ Update failed:', error);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
4
47
|
import.meta.hot.accept((newModule) => {
|
|
5
48
|
// console.log('[HMR Browser] Update accepted for ${id}');
|
|
6
49
|
|
|
@@ -22,32 +65,9 @@ if (import.meta.hot) {
|
|
|
22
65
|
// console.error('[HMR Browser] ComponentRegistry not found!');
|
|
23
66
|
return;
|
|
24
67
|
}
|
|
68
|
+
cleanTimers(newModule);
|
|
69
|
+
updateComponents(newModule);
|
|
25
70
|
|
|
26
|
-
console.log('[HMR Browser] Calling ComponentRegistry.update()');
|
|
27
|
-
try {
|
|
28
|
-
for(const componentId of componentIds) {
|
|
29
|
-
ComponentRegistry.cleanTimer(componentId);
|
|
30
|
-
}
|
|
31
|
-
ComponentRegistry.cleanTimer('${id}')
|
|
32
|
-
console.log('[HMR Browser] ✓ Clean timer successful');
|
|
33
|
-
} catch (error) {
|
|
34
|
-
console.error('[HMR Browser] ✗ Clean timers failed:', error);
|
|
35
|
-
}
|
|
36
|
-
try {
|
|
37
|
-
for(const componentId of componentIds) {
|
|
38
|
-
ComponentRegistry.cleanTimer(componentId);
|
|
39
|
-
}
|
|
40
|
-
ComponentRegistry.cleanTimer('${id}')
|
|
41
|
-
|
|
42
|
-
for(const componentId of componentIds) {
|
|
43
|
-
// console.log('[HMR Browser] ComponentId : '+componentId);
|
|
44
|
-
ComponentRegistry.update(componentId, newModule.default, '${id}');
|
|
45
|
-
}
|
|
46
|
-
ComponentRegistry.update('${id}', newModule.default, '${id}');
|
|
47
|
-
// console.log('[HMR Browser] ✓ Update successful');
|
|
48
|
-
} catch (error) {
|
|
49
|
-
console.error('[HMR Browser] ✗ Update failed:', error);
|
|
50
|
-
}
|
|
51
71
|
});
|
|
52
72
|
|
|
53
73
|
import.meta.hot.on('vite:error', (payload) => {
|
|
@@ -32,16 +32,22 @@ export default function transformForHrm(code, id, options = {}) {
|
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
34
|
const fnName = path.node.id.name;
|
|
35
|
+
let isDefaultExport = path.parent.type === 'ExportDefaultDeclaration';
|
|
35
36
|
if(!/^[A-Z]/.test(fnName)) {
|
|
36
37
|
return;
|
|
37
38
|
}
|
|
38
39
|
const componentId = `${id}::${fnName}`;
|
|
39
|
-
|
|
40
|
+
const componentDetails = {
|
|
41
|
+
id: componentId,
|
|
42
|
+
name: fnName,
|
|
43
|
+
isDefault: false
|
|
44
|
+
};
|
|
45
|
+
componentIds.push(componentDetails);
|
|
40
46
|
|
|
41
47
|
const wrappedCall = t.callExpression(
|
|
42
48
|
t.memberExpression(
|
|
43
49
|
t.identifier('ComponentRegistry'),
|
|
44
|
-
t.identifier('register')
|
|
50
|
+
t.identifier('register'),
|
|
45
51
|
),
|
|
46
52
|
[
|
|
47
53
|
t.stringLiteral(componentId),
|
|
@@ -50,11 +56,12 @@ export default function transformForHrm(code, id, options = {}) {
|
|
|
50
56
|
path.node.params,
|
|
51
57
|
path.node.body,
|
|
52
58
|
),
|
|
53
|
-
]
|
|
59
|
+
],
|
|
54
60
|
);
|
|
55
61
|
|
|
56
62
|
// Cas — export default function HomePage() {}
|
|
57
63
|
if(path.parent.type === 'ExportDefaultDeclaration') {
|
|
64
|
+
componentDetails.isDefault = true;
|
|
58
65
|
const varDeclaration = t.variableDeclaration('const', [
|
|
59
66
|
t.variableDeclarator(t.identifier(fnName), wrappedCall),
|
|
60
67
|
]);
|
|
@@ -82,6 +89,7 @@ export default function transformForHrm(code, id, options = {}) {
|
|
|
82
89
|
}
|
|
83
90
|
const fnName = path.node.id.name;
|
|
84
91
|
const isComponent = /^[A-Z]/.test(fnName);
|
|
92
|
+
|
|
85
93
|
if (!isComponent) {
|
|
86
94
|
return;
|
|
87
95
|
}
|
|
@@ -89,7 +97,11 @@ export default function transformForHrm(code, id, options = {}) {
|
|
|
89
97
|
return;
|
|
90
98
|
}
|
|
91
99
|
const componentId = `${id}::${fnName}`;
|
|
92
|
-
componentIds.push(
|
|
100
|
+
componentIds.push({
|
|
101
|
+
id: componentId,
|
|
102
|
+
name: fnName,
|
|
103
|
+
isDefault: (path.parent.type === 'ExportDefaultDeclaration'),
|
|
104
|
+
});
|
|
93
105
|
|
|
94
106
|
const wrappedCall = t.callExpression(
|
|
95
107
|
t.memberExpression(
|
|
@@ -106,6 +118,19 @@ export default function transformForHrm(code, id, options = {}) {
|
|
|
106
118
|
path.node.init = wrappedCall;
|
|
107
119
|
// path.skip();
|
|
108
120
|
},
|
|
121
|
+
ExportDefaultDeclaration(path) {
|
|
122
|
+
const declaration = path.node.declaration;
|
|
123
|
+
|
|
124
|
+
if (t.isIdentifier(declaration)) {
|
|
125
|
+
const fnName = declaration.name;
|
|
126
|
+
|
|
127
|
+
const findPath = componentIds.find((item) => item.name === fnName);
|
|
128
|
+
if(findPath) {
|
|
129
|
+
findPath.isDefault = true;
|
|
130
|
+
// return;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
},
|
|
109
134
|
CallExpression(path) {
|
|
110
135
|
const callee = path.node.callee;
|
|
111
136
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "native-document",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.283",
|
|
4
4
|
"description": "A reactive JavaScript framework that preserves native DOM simplicity without sacrificing modern features",
|
|
5
5
|
"author": "AfroCodeur <https://github.com/afrocodeur>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {Observable as ObservableOriginal} from './Observable';
|
|
2
2
|
import {TRANSFORMED_OBSERVABLE_ID} from '../../../devtools/constantes';
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const HrmGlobalObservableRegistry = new Map();
|
|
5
5
|
|
|
6
6
|
const overrideMethods = ['array', 'init', 'object', 'json', 'computed', 'batch', 'auto'];
|
|
7
|
-
const noObservableOverride = ['ref', 'resource'];
|
|
7
|
+
const noObservableOverride = ['ref', 'resource', 'from'];
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
const override = (callback) => {
|
|
@@ -18,7 +18,7 @@ const override = (callback) => {
|
|
|
18
18
|
|
|
19
19
|
if(scope === null) {
|
|
20
20
|
const fullId = id+':'+name;
|
|
21
|
-
const existing =
|
|
21
|
+
const existing = HrmGlobalObservableRegistry.get(fullId);
|
|
22
22
|
if(existing) {
|
|
23
23
|
if(existing.value !== value) {
|
|
24
24
|
existing.value = value;
|
|
@@ -27,7 +27,7 @@ const override = (callback) => {
|
|
|
27
27
|
return existing.observable;
|
|
28
28
|
}
|
|
29
29
|
const observable = callback(value, configs);
|
|
30
|
-
|
|
30
|
+
HrmGlobalObservableRegistry.set(fullId, {
|
|
31
31
|
value,
|
|
32
32
|
observable
|
|
33
33
|
});
|
|
@@ -155,3 +155,10 @@ ObservableQuery.prototype.push = function(value) {
|
|
|
155
155
|
});
|
|
156
156
|
return this.flush();
|
|
157
157
|
};
|
|
158
|
+
|
|
159
|
+
ObservableQuery.prototype.unshift = function(value) {
|
|
160
|
+
this.$currentResultData.forEach((element) => {
|
|
161
|
+
element.unshift && element.unshift(value);
|
|
162
|
+
});
|
|
163
|
+
return this.flush();
|
|
164
|
+
};
|