@jsenv/navi 0.0.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/index.js +51 -0
- package/package.json +38 -0
- package/src/action_private_properties.js +11 -0
- package/src/action_proxy_test.html +353 -0
- package/src/action_run_states.js +5 -0
- package/src/actions.js +1377 -0
- package/src/browser_integration/browser_integration.js +191 -0
- package/src/browser_integration/document_back_and_forward.js +17 -0
- package/src/browser_integration/document_loading_signal.js +100 -0
- package/src/browser_integration/document_state_signal.js +9 -0
- package/src/browser_integration/document_url_signal.js +9 -0
- package/src/browser_integration/use_is_visited.js +19 -0
- package/src/browser_integration/via_history.js +199 -0
- package/src/browser_integration/via_navigation.js +168 -0
- package/src/components/action_execution/form_context.js +8 -0
- package/src/components/action_execution/render_actionable_component.jsx +27 -0
- package/src/components/action_execution/use_action.js +330 -0
- package/src/components/action_execution/use_execute_action.js +161 -0
- package/src/components/action_renderer.jsx +136 -0
- package/src/components/collect_form_element_values.js +79 -0
- package/src/components/demos/0_button_demo.html +155 -0
- package/src/components/demos/1_checkbox_demo.html +257 -0
- package/src/components/demos/2_input_textual_demo.html +354 -0
- package/src/components/demos/3_radio_demo.html +222 -0
- package/src/components/demos/4_select_demo.html +104 -0
- package/src/components/demos/5_list_scrollable_demo.html +153 -0
- package/src/components/demos/action/0_button_demo.html +204 -0
- package/src/components/demos/action/10_shortcuts_demo.html +189 -0
- package/src/components/demos/action/11_nested_shortcuts_demo.html +401 -0
- package/src/components/demos/action/1_input_text_demo.html +461 -0
- package/src/components/demos/action/2_form_multiple.html +303 -0
- package/src/components/demos/action/3_details_demo.html +172 -0
- package/src/components/demos/action/4_input_checkbox_demo.html +611 -0
- package/src/components/demos/action/6_checkbox_list_demo.html +109 -0
- package/src/components/demos/action/7_radio_list_demo.html +217 -0
- package/src/components/demos/action/8_editable_text_demo.html +442 -0
- package/src/components/demos/action/9_link_demo.html +172 -0
- package/src/components/demos/demo.md +0 -0
- package/src/components/demos/route/basic/basic.html +14 -0
- package/src/components/demos/route/basic/basic_route_demo.jsx +224 -0
- package/src/components/demos/route/multi/multi.html +14 -0
- package/src/components/demos/route/multi/multi_route_demo.jsx +277 -0
- package/src/components/details/details.jsx +248 -0
- package/src/components/details/summary_marker.jsx +141 -0
- package/src/components/editable_text/editable_text.jsx +96 -0
- package/src/components/error_boundary_context.js +9 -0
- package/src/components/form.jsx +144 -0
- package/src/components/input/button.jsx +333 -0
- package/src/components/input/checkbox_list.jsx +294 -0
- package/src/components/input/field.jsx +61 -0
- package/src/components/input/field_css.js +118 -0
- package/src/components/input/input.jsx +15 -0
- package/src/components/input/input_checkbox.jsx +370 -0
- package/src/components/input/input_radio.jsx +299 -0
- package/src/components/input/input_textual.jsx +338 -0
- package/src/components/input/radio_list.jsx +283 -0
- package/src/components/input/select.jsx +273 -0
- package/src/components/input/use_form_event.js +20 -0
- package/src/components/input/use_on_change.js +12 -0
- package/src/components/link/link.jsx +291 -0
- package/src/components/loader/loader_background.jsx +324 -0
- package/src/components/loader/loading_spinner.jsx +68 -0
- package/src/components/loader/network_speed.js +83 -0
- package/src/components/loader/rectangle_loading.jsx +225 -0
- package/src/components/route.jsx +15 -0
- package/src/components/selection/selection.js +5 -0
- package/src/components/selection/selection_context.jsx +262 -0
- package/src/components/shortcut/os.js +9 -0
- package/src/components/shortcut/shortcut_context.jsx +390 -0
- package/src/components/use_action_events.js +37 -0
- package/src/components/use_auto_focus.js +43 -0
- package/src/components/use_debounce_true.js +31 -0
- package/src/components/use_focus_group.js +19 -0
- package/src/components/use_initial_value.js +104 -0
- package/src/components/use_is_visited.js +19 -0
- package/src/components/use_ref_array.js +38 -0
- package/src/components/use_signal_sync.js +50 -0
- package/src/components/use_state_array.js +40 -0
- package/src/docs/actions.md +228 -0
- package/src/docs/demos/resource/action_status.jsx +42 -0
- package/src/docs/demos/resource/demo.md +1 -0
- package/src/docs/demos/resource/resource_demo_0.html +84 -0
- package/src/docs/demos/resource/resource_demo_10_post_gc.html +364 -0
- package/src/docs/demos/resource/resource_demo_11_describe_many.html +362 -0
- package/src/docs/demos/resource/resource_demo_2.html +173 -0
- package/src/docs/demos/resource/resource_demo_3_filtered_users.html +415 -0
- package/src/docs/demos/resource/resource_demo_4_details.html +284 -0
- package/src/docs/demos/resource/resource_demo_5_renderer_lazy.html +115 -0
- package/src/docs/demos/resource/resource_demo_6_gc.html +217 -0
- package/src/docs/demos/resource/resource_demo_7_child_gc.html +240 -0
- package/src/docs/demos/resource/resource_demo_8_proxy_gc.html +319 -0
- package/src/docs/demos/resource/resource_demo_9_describe_one.html +472 -0
- package/src/docs/demos/resource/tata.jsx +3 -0
- package/src/docs/demos/resource/toto.jsx +3 -0
- package/src/docs/demos/user_nav/user_nav.html +12 -0
- package/src/docs/demos/user_nav/user_nav.jsx +330 -0
- package/src/docs/resource_dependencies.md +103 -0
- package/src/docs/resource_with_params.md +80 -0
- package/src/notes.md +13 -0
- package/src/route/route.js +518 -0
- package/src/route/route.test.html +228 -0
- package/src/store/array_signal_store.js +537 -0
- package/src/store/local_storage_signal.js +17 -0
- package/src/store/resource_graph.js +1303 -0
- package/src/store/tests/resource_graph_autoreload_demo.html +12 -0
- package/src/store/tests/resource_graph_autoreload_demo.jsx +964 -0
- package/src/store/tests/resource_graph_dependencies.test.js +95 -0
- package/src/store/value_in_local_storage.js +187 -0
- package/src/symbol_object_signal.js +1 -0
- package/src/use_action_data.js +10 -0
- package/src/use_action_status.js +47 -0
- package/src/utils/add_many_event_listeners.js +15 -0
- package/src/utils/array_add_remove.js +61 -0
- package/src/utils/array_signal.js +15 -0
- package/src/utils/compare_two_js_values.js +172 -0
- package/src/utils/execute_with_cleanup.js +21 -0
- package/src/utils/get_caller_info.js +85 -0
- package/src/utils/iterable_weak_set.js +62 -0
- package/src/utils/js_value_weak_map.js +162 -0
- package/src/utils/js_value_weak_map_demo.html +690 -0
- package/src/utils/merge_two_js_values.js +53 -0
- package/src/utils/stringify_for_display.js +150 -0
- package/src/utils/weak_effect.js +48 -0
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" href="data:," />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>Resource GC Test</title>
|
|
8
|
+
<style>
|
|
9
|
+
body {
|
|
10
|
+
font-family: Arial, sans-serif;
|
|
11
|
+
padding: 20px;
|
|
12
|
+
max-width: 800px;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.controls {
|
|
16
|
+
margin-bottom: 20px;
|
|
17
|
+
padding: 15px;
|
|
18
|
+
border: 1px solid #ccc;
|
|
19
|
+
background: #f9f9f9;
|
|
20
|
+
border-radius: 4px;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.stats {
|
|
24
|
+
margin-bottom: 20px;
|
|
25
|
+
padding: 15px;
|
|
26
|
+
border: 1px solid #007acc;
|
|
27
|
+
background: #e6f3ff;
|
|
28
|
+
border-radius: 4px;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.stats div {
|
|
32
|
+
margin-bottom: 5px;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.stats .debug-info {
|
|
36
|
+
font-size: 12px;
|
|
37
|
+
color: #666;
|
|
38
|
+
margin-top: 10px;
|
|
39
|
+
padding-top: 10px;
|
|
40
|
+
border-top: 1px solid #ccc;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.numbers {
|
|
44
|
+
display: grid;
|
|
45
|
+
grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
|
|
46
|
+
gap: 10px;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.number-item {
|
|
50
|
+
padding: 20px;
|
|
51
|
+
text-align: center;
|
|
52
|
+
border: 1px solid #ddd;
|
|
53
|
+
border-radius: 4px;
|
|
54
|
+
background: white;
|
|
55
|
+
font-size: 24px;
|
|
56
|
+
font-weight: bold;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
button {
|
|
60
|
+
padding: 10px 20px;
|
|
61
|
+
margin: 5px;
|
|
62
|
+
border: none;
|
|
63
|
+
border-radius: 4px;
|
|
64
|
+
cursor: pointer;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.primary {
|
|
68
|
+
background: #007acc;
|
|
69
|
+
color: white;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.danger {
|
|
73
|
+
background: #dc3545;
|
|
74
|
+
color: white;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.secondary {
|
|
78
|
+
background: #6c757d;
|
|
79
|
+
color: white;
|
|
80
|
+
}
|
|
81
|
+
</style>
|
|
82
|
+
</head>
|
|
83
|
+
<body>
|
|
84
|
+
<h1>Resource Garbage Collection Test</h1>
|
|
85
|
+
|
|
86
|
+
<div class="controls">
|
|
87
|
+
<button class="primary" id="addNumber">Add Random Number</button>
|
|
88
|
+
<button class="secondary" id="forceGC">Force Garbage Collection</button>
|
|
89
|
+
<button class="danger" id="clearAll">Clear All Numbers</button>
|
|
90
|
+
</div>
|
|
91
|
+
|
|
92
|
+
<div class="stats">
|
|
93
|
+
<div>
|
|
94
|
+
<strong>Numbers Count:</strong> <span id="numbersCount">0</span>
|
|
95
|
+
</div>
|
|
96
|
+
<div>
|
|
97
|
+
<strong>Alive POST Actions:</strong>
|
|
98
|
+
<span id="postActionsCount">0</span>
|
|
99
|
+
</div>
|
|
100
|
+
<div>
|
|
101
|
+
<strong>Total Actions in Registry:</strong>
|
|
102
|
+
<span id="totalActionsCount">0</span>
|
|
103
|
+
</div>
|
|
104
|
+
<!-- ✅ Add activation stats display -->
|
|
105
|
+
<div class="debug-info">
|
|
106
|
+
<div>
|
|
107
|
+
<strong>Activation WeakSet:</strong>
|
|
108
|
+
<span id="activationStats">-</span>
|
|
109
|
+
</div>
|
|
110
|
+
<div>
|
|
111
|
+
<strong>Child Action WeakSet:</strong> <span id="childStats">-</span>
|
|
112
|
+
</div>
|
|
113
|
+
</div>
|
|
114
|
+
</div>
|
|
115
|
+
|
|
116
|
+
<div id="numbers" class="numbers"></div>
|
|
117
|
+
|
|
118
|
+
<script type="module" jsenv-type="module/jsx">
|
|
119
|
+
import { render } from "preact";
|
|
120
|
+
import { useState, useEffect } from "preact/hooks";
|
|
121
|
+
import {
|
|
122
|
+
createAction,
|
|
123
|
+
// eslint-disable-next-line no-unused-vars
|
|
124
|
+
ActionRenderer,
|
|
125
|
+
} from "@jsenv/navi";
|
|
126
|
+
import { getActionPrivateProperties } from "../../../action_private_properties.js";
|
|
127
|
+
|
|
128
|
+
// ✅ Test data store
|
|
129
|
+
const numbersStore = [];
|
|
130
|
+
let nextId = 1;
|
|
131
|
+
|
|
132
|
+
const numberListAction = createAction(
|
|
133
|
+
() => {
|
|
134
|
+
return numbersStore;
|
|
135
|
+
},
|
|
136
|
+
{ name: "list" },
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
const postNumberAction = createAction(
|
|
140
|
+
({ value }) => {
|
|
141
|
+
console.log(`Creating number: ${value}`);
|
|
142
|
+
const newNumber = { id: nextId++, value };
|
|
143
|
+
numbersStore.push(newNumber);
|
|
144
|
+
return newNumber;
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
name: "post",
|
|
148
|
+
},
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const deleteAllNumbersAction = createAction(
|
|
152
|
+
() => {
|
|
153
|
+
console.log("Deleting all numbers");
|
|
154
|
+
numbersStore.length = 0;
|
|
155
|
+
const deletedIds = numbersStore.map((num) => num.id);
|
|
156
|
+
return deletedIds;
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
name: "delete",
|
|
160
|
+
},
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
numberListAction.reload();
|
|
164
|
+
|
|
165
|
+
// ✅ Helper function to get registry stats
|
|
166
|
+
const getRegistryStats = () => {
|
|
167
|
+
const { loadingSet, settledSet } =
|
|
168
|
+
window.__actions__.getActivationInfo();
|
|
169
|
+
let alivePostActions = 0;
|
|
170
|
+
|
|
171
|
+
let total = 0;
|
|
172
|
+
for (const action of new Set([...loadingSet, ...settledSet])) {
|
|
173
|
+
total++;
|
|
174
|
+
if (action.name && action.name.includes("post")) {
|
|
175
|
+
alivePostActions++;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// ✅ Get activation registry stats
|
|
180
|
+
const activationStats =
|
|
181
|
+
window.__actions__.activationWeakSet?.getStats() || {
|
|
182
|
+
total: 0,
|
|
183
|
+
alive: 0,
|
|
184
|
+
dead: 0,
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// ✅ Get child action stats
|
|
188
|
+
const privateProps = getActionPrivateProperties(postNumberAction);
|
|
189
|
+
const childStats = privateProps.childActionWeakSet.getStats();
|
|
190
|
+
|
|
191
|
+
return {
|
|
192
|
+
total,
|
|
193
|
+
alivePostActions,
|
|
194
|
+
activation: activationStats,
|
|
195
|
+
child: childStats,
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
// ✅ Update stats periodically
|
|
200
|
+
const updateStats = () => {
|
|
201
|
+
const stats = getRegistryStats();
|
|
202
|
+
|
|
203
|
+
document.getElementById("numbersCount").textContent =
|
|
204
|
+
numbersStore.length;
|
|
205
|
+
document.getElementById("postActionsCount").textContent =
|
|
206
|
+
stats.alivePostActions;
|
|
207
|
+
document.getElementById("totalActionsCount").textContent = stats.total;
|
|
208
|
+
|
|
209
|
+
// ✅ Display activation stats
|
|
210
|
+
const activationStatsEl = document.getElementById("activationStats");
|
|
211
|
+
if (activationStatsEl) {
|
|
212
|
+
activationStatsEl.textContent = `Total: ${stats.activation.total}, Alive: ${stats.activation.alive}, Dead: ${stats.activation.dead}`;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// ✅ Display child stats
|
|
216
|
+
const childStatsEl = document.getElementById("childStats");
|
|
217
|
+
if (childStatsEl) {
|
|
218
|
+
if (stats.child.total > 0) {
|
|
219
|
+
childStatsEl.textContent = `Total: ${stats.child.total}, Alive: ${stats.child.alive}, Dead: ${stats.child.dead}`;
|
|
220
|
+
} else {
|
|
221
|
+
childStatsEl.textContent = "No cached child actions";
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
setInterval(() => {
|
|
227
|
+
updateStats();
|
|
228
|
+
}, 100);
|
|
229
|
+
|
|
230
|
+
// ✅ Enhanced GC function with force cleanup
|
|
231
|
+
const forceGCAndCheck = async () => {
|
|
232
|
+
console.log("🔄 Forcing cleanup and GC...");
|
|
233
|
+
|
|
234
|
+
// ✅ Force cleanup of all weak sets/maps before GC
|
|
235
|
+
let cleanupStats = {};
|
|
236
|
+
|
|
237
|
+
// Force activation cleanup
|
|
238
|
+
if (window.__actions__?.activationWeakSet?.forceCleanup) {
|
|
239
|
+
cleanupStats.activation =
|
|
240
|
+
window.__actions__.activationWeakSet.forceCleanup();
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Force child action cleanup
|
|
244
|
+
|
|
245
|
+
const privateProps = getActionPrivateProperties(postNumberAction);
|
|
246
|
+
if (privateProps.childActionWeakSet.forceCleanup) {
|
|
247
|
+
cleanupStats.child = privateProps.childActionWeakSet.forceCleanup();
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Force browser GC
|
|
251
|
+
if (window.gc) {
|
|
252
|
+
window.gc();
|
|
253
|
+
console.log("🗑️ Browser GC called");
|
|
254
|
+
} else {
|
|
255
|
+
// Fallback: créer de la pression mémoire
|
|
256
|
+
console.log("🗑️ Creating memory pressure...");
|
|
257
|
+
const arrays = [];
|
|
258
|
+
for (let i = 0; i < 100; i++) {
|
|
259
|
+
arrays.push(new Array(100000).fill(Math.random()));
|
|
260
|
+
}
|
|
261
|
+
// Laisser les arrays être collectées
|
|
262
|
+
arrays.length = 0;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Attendre un peu pour que le GC ait le temps de s'exécuter
|
|
266
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
267
|
+
|
|
268
|
+
updateStats();
|
|
269
|
+
|
|
270
|
+
// Vérifier le résultat
|
|
271
|
+
const stats = getRegistryStats();
|
|
272
|
+
const { alivePostActions } = stats;
|
|
273
|
+
|
|
274
|
+
console.log("📊 Final stats:", {
|
|
275
|
+
alivePostActions,
|
|
276
|
+
activation: stats.activation,
|
|
277
|
+
child: stats.child,
|
|
278
|
+
cleanup: cleanupStats,
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
if (alivePostActions === 0) {
|
|
282
|
+
console.log("✅ SUCCESS: All POST actions were garbage collected!");
|
|
283
|
+
} else {
|
|
284
|
+
console.log(
|
|
285
|
+
`❌ ISSUE: ${alivePostActions} POST actions are still alive`,
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
// eslint-disable-next-line no-unused-vars
|
|
291
|
+
const TestApp = () => {
|
|
292
|
+
const [, forceUpdate] = useState({});
|
|
293
|
+
|
|
294
|
+
useEffect(() => {
|
|
295
|
+
const interval = setInterval(() => {
|
|
296
|
+
forceUpdate({});
|
|
297
|
+
}, 100);
|
|
298
|
+
|
|
299
|
+
return () => clearInterval(interval);
|
|
300
|
+
}, []);
|
|
301
|
+
|
|
302
|
+
return (
|
|
303
|
+
<ActionRenderer action={numberListAction}>
|
|
304
|
+
{(numbers) => (
|
|
305
|
+
<>
|
|
306
|
+
{numbers.map((num) => (
|
|
307
|
+
<div key={num.id} className="number-item">
|
|
308
|
+
{num.value}
|
|
309
|
+
</div>
|
|
310
|
+
))}
|
|
311
|
+
</>
|
|
312
|
+
)}
|
|
313
|
+
</ActionRenderer>
|
|
314
|
+
);
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
// ✅ Event listeners
|
|
318
|
+
document
|
|
319
|
+
.getElementById("addNumber")
|
|
320
|
+
.addEventListener("click", async () => {
|
|
321
|
+
const randomValue = Math.floor(Math.random() * 1000);
|
|
322
|
+
await postNumberAction.bindParams({ value: randomValue }).reload();
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
document
|
|
326
|
+
.getElementById("forceGC")
|
|
327
|
+
.addEventListener("click", forceGCAndCheck);
|
|
328
|
+
|
|
329
|
+
document
|
|
330
|
+
.getElementById("clearAll")
|
|
331
|
+
.addEventListener("click", async () => {
|
|
332
|
+
await deleteAllNumbersAction.reload();
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
// ✅ Render the app
|
|
336
|
+
render(<TestApp />, document.getElementById("numbers"));
|
|
337
|
+
|
|
338
|
+
// ✅ Console helpers for manual testing
|
|
339
|
+
window.testHelpers = {
|
|
340
|
+
getRegistryStats,
|
|
341
|
+
updateStats,
|
|
342
|
+
numbersStore,
|
|
343
|
+
actions: {
|
|
344
|
+
postNumberAction,
|
|
345
|
+
deleteAllNumbersAction,
|
|
346
|
+
},
|
|
347
|
+
// ✅ Add debug helper
|
|
348
|
+
debugReferences: () => {
|
|
349
|
+
const stats = getRegistryStats();
|
|
350
|
+
console.table(stats);
|
|
351
|
+
return stats;
|
|
352
|
+
},
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
console.log("🧪 GC Test loaded!");
|
|
356
|
+
console.log(
|
|
357
|
+
"📊 Use window.testHelpers.debugReferences() to check all registry stats",
|
|
358
|
+
);
|
|
359
|
+
console.log(
|
|
360
|
+
"🗑️ Run Chrome with --js-flags='--expose-gc' to enable manual GC",
|
|
361
|
+
);
|
|
362
|
+
</script>
|
|
363
|
+
</body>
|
|
364
|
+
</html>
|