what-core 0.5.6 → 0.6.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/README.md +8 -6
- package/dist/components.js +1 -1
- package/dist/dom.js +127 -451
- package/dist/h.js +1 -1
- package/dist/hooks.js +4 -0
- package/dist/index.js +5919 -123
- package/dist/index.js.map +7 -0
- package/dist/index.min.js +123 -0
- package/dist/index.min.js.map +7 -0
- package/dist/jsx-dev-runtime.js +51 -0
- package/dist/jsx-dev-runtime.js.map +7 -0
- package/dist/jsx-dev-runtime.min.js +2 -0
- package/dist/jsx-dev-runtime.min.js.map +7 -0
- package/dist/jsx-runtime.js +49 -0
- package/dist/jsx-runtime.js.map +7 -0
- package/dist/jsx-runtime.min.js +2 -0
- package/dist/jsx-runtime.min.js.map +7 -0
- package/dist/reactive.js +175 -11
- package/dist/render.js +1502 -273
- package/dist/render.js.map +7 -0
- package/dist/render.min.js +2 -0
- package/dist/render.min.js.map +7 -0
- package/dist/testing.js +1204 -144
- package/dist/testing.js.map +7 -0
- package/dist/testing.min.js +2 -0
- package/dist/testing.min.js.map +7 -0
- package/dist/what.js +3 -2
- package/package.json +9 -4
- package/src/agent-context.js +126 -0
- package/src/components.js +10 -34
- package/src/dom.js +225 -745
- package/src/errors.js +253 -0
- package/src/guardrails.js +224 -0
- package/src/h.js +3 -3
- package/src/hooks.js +121 -52
- package/src/index.js +38 -4
- package/src/reactive.js +389 -41
- package/src/render.js +445 -14
- package/src/testing.js +169 -1
- package/src/warnings.js +110 -0
package/src/warnings.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// What Framework - Dev-mode Warning System
|
|
2
|
+
// Helpful, not noisy: each unique warning fires only once.
|
|
3
|
+
// All warnings are dev-only and tree-shaken in production builds.
|
|
4
|
+
|
|
5
|
+
import { __DEV__ } from './reactive.js';
|
|
6
|
+
|
|
7
|
+
// Track which warnings have already been emitted (fire-once per unique key)
|
|
8
|
+
const _emitted = new Set();
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Emit a dev-mode warning. Fires only once per unique key.
|
|
12
|
+
* @param {string} key - Unique identifier for de-duplication
|
|
13
|
+
* @param {string} message - Warning message
|
|
14
|
+
*/
|
|
15
|
+
export function warn(key, message) {
|
|
16
|
+
if (!__DEV__) return;
|
|
17
|
+
if (_emitted.has(key)) return;
|
|
18
|
+
_emitted.add(key);
|
|
19
|
+
console.warn(message);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Reset all emitted warnings (for testing).
|
|
24
|
+
*/
|
|
25
|
+
export function _resetWarnings() {
|
|
26
|
+
_emitted.clear();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Check if a warning has been emitted (for testing).
|
|
31
|
+
* @param {string} key
|
|
32
|
+
* @returns {boolean}
|
|
33
|
+
*/
|
|
34
|
+
export function _wasWarned(key) {
|
|
35
|
+
return _emitted.has(key);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// --- Warning functions ---
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Warn when a signal is used in JSX without being called.
|
|
42
|
+
* Detects: {count} instead of {count()} where count is a signal function.
|
|
43
|
+
* @param {string} signalName - The signal's debug name
|
|
44
|
+
* @param {string} [componentName] - The component where it occurred
|
|
45
|
+
*/
|
|
46
|
+
export function warnMissingSignalRead(signalName, componentName) {
|
|
47
|
+
if (!__DEV__) return;
|
|
48
|
+
const ctx = componentName ? ` in <${componentName}>` : '';
|
|
49
|
+
warn(
|
|
50
|
+
`missing-read:${signalName}:${componentName || ''}`,
|
|
51
|
+
`[what] Warning: Signal '${signalName}' used without being called${ctx}. Did you mean {${signalName}()}?`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Warn when a signal is written during render (component function execution).
|
|
57
|
+
* Writes should happen in effects or event handlers, not during render.
|
|
58
|
+
* @param {string} signalName - The signal's debug name
|
|
59
|
+
* @param {string} [componentName] - The component where it occurred
|
|
60
|
+
*/
|
|
61
|
+
export function warnSignalWriteDuringRender(signalName, componentName) {
|
|
62
|
+
if (!__DEV__) return;
|
|
63
|
+
const ctx = componentName ? ` of <${componentName}>` : '';
|
|
64
|
+
warn(
|
|
65
|
+
`write-during-render:${signalName}:${componentName || ''}`,
|
|
66
|
+
`[what] Warning: Signal '${signalName}' written during render${ctx}. Move to effect or event handler.`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Warn when an effect adds an event listener but has no cleanup return.
|
|
72
|
+
* @param {string} [componentName] - The component where it occurred
|
|
73
|
+
*/
|
|
74
|
+
export function warnEffectWithoutCleanup(componentName) {
|
|
75
|
+
if (!__DEV__) return;
|
|
76
|
+
const ctx = componentName ? ` in <${componentName}>` : '';
|
|
77
|
+
warn(
|
|
78
|
+
`effect-no-cleanup:${componentName || 'unknown'}`,
|
|
79
|
+
`[what] Warning: Effect${ctx} adds event listener but has no cleanup. Return a cleanup function from the effect to avoid memory leaks.`
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Warn when rendering a large list without keys.
|
|
85
|
+
* @param {number} count - Number of items in the list
|
|
86
|
+
* @param {string} [componentName] - The component where it occurred
|
|
87
|
+
*/
|
|
88
|
+
export function warnLargeListWithoutKeys(count, componentName) {
|
|
89
|
+
if (!__DEV__) return;
|
|
90
|
+
const ctx = componentName ? ` in <${componentName}>` : '';
|
|
91
|
+
warn(
|
|
92
|
+
`no-keys:${componentName || 'unknown'}`,
|
|
93
|
+
`[what] Warning: Rendering ${count} items without keys${ctx}. Add key props for efficient DOM updates.`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Warn when a signal is created but never read.
|
|
99
|
+
* Called lazily (e.g., on component unmount or root dispose).
|
|
100
|
+
* @param {string} signalName - The signal's debug name
|
|
101
|
+
* @param {string} [componentName] - The component where it occurred
|
|
102
|
+
*/
|
|
103
|
+
export function warnUnusedSignal(signalName, componentName) {
|
|
104
|
+
if (!__DEV__) return;
|
|
105
|
+
const ctx = componentName ? ` in <${componentName}>` : '';
|
|
106
|
+
warn(
|
|
107
|
+
`unused-signal:${signalName}:${componentName || ''}`,
|
|
108
|
+
`[what] Warning: Signal '${signalName}' created${ctx} but never read.`
|
|
109
|
+
);
|
|
110
|
+
}
|