what-core 0.3.0 → 0.4.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/dist/a11y.js +22 -7
- package/dist/animation.js +9 -1
- package/dist/components.js +61 -23
- package/dist/data.js +253 -59
- package/dist/dom.js +196 -24
- package/dist/form.js +112 -44
- package/dist/helpers.js +73 -10
- package/dist/hooks.js +63 -22
- package/dist/index.js +6 -2
- package/dist/reactive.js +189 -29
- package/dist/render.js +716 -0
- package/dist/scheduler.js +10 -5
- package/dist/store.js +18 -8
- package/package.json +10 -1
- package/src/a11y.js +22 -7
- package/src/animation.js +9 -1
- package/src/components.js +61 -23
- package/src/data.js +253 -59
- package/src/dom.js +222 -24
- package/src/form.js +112 -44
- package/src/h.js +3 -0
- package/src/helpers.js +73 -10
- package/src/hooks.js +63 -22
- package/src/index.js +6 -2
- package/src/jsx-dev-runtime.js +19 -0
- package/src/jsx-runtime.js +21 -0
- package/src/reactive.js +208 -39
- package/src/render.js +716 -0
- package/src/scheduler.js +10 -5
- package/src/store.js +18 -8
package/src/scheduler.js
CHANGED
|
@@ -98,12 +98,17 @@ export function mutate(fn) {
|
|
|
98
98
|
import { effect } from './reactive.js';
|
|
99
99
|
|
|
100
100
|
export function useScheduledEffect(readFn, writeFn) {
|
|
101
|
+
const effectKey = Symbol('scheduledEffect');
|
|
101
102
|
return effect(() => {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
// Use raf() to debounce: only the latest callback runs per frame,
|
|
104
|
+
// avoiding creating new closures on every signal change.
|
|
105
|
+
raf(effectKey, () => {
|
|
106
|
+
scheduleRead(() => {
|
|
107
|
+
const data = readFn();
|
|
108
|
+
if (writeFn) {
|
|
109
|
+
scheduleWrite(() => writeFn(data));
|
|
110
|
+
}
|
|
111
|
+
});
|
|
107
112
|
});
|
|
108
113
|
});
|
|
109
114
|
}
|
package/src/store.js
CHANGED
|
@@ -15,11 +15,21 @@ import { signal, computed, batch } from './reactive.js';
|
|
|
15
15
|
// addItem(item) { /* this is an action */ },
|
|
16
16
|
// });
|
|
17
17
|
|
|
18
|
-
export function
|
|
18
|
+
export function derived(fn) {
|
|
19
19
|
fn._storeComputed = true;
|
|
20
20
|
return fn;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
// Deprecated alias — use derived() instead
|
|
24
|
+
let _storeComputedWarned = false;
|
|
25
|
+
export function storeComputed(fn) {
|
|
26
|
+
if (!_storeComputedWarned) {
|
|
27
|
+
_storeComputedWarned = true;
|
|
28
|
+
console.warn('[what] storeComputed() is deprecated. Use derived() instead.');
|
|
29
|
+
}
|
|
30
|
+
return derived(fn);
|
|
31
|
+
}
|
|
32
|
+
|
|
23
33
|
// --- createStore ---
|
|
24
34
|
// Creates a reactive store with actions. Each key becomes a signal.
|
|
25
35
|
//
|
|
@@ -78,6 +88,7 @@ export function createStore(definition) {
|
|
|
78
88
|
get(_, prop) {
|
|
79
89
|
if (signals[prop]) return signals[prop].peek();
|
|
80
90
|
if (computeds[prop]) return computeds[prop].peek();
|
|
91
|
+
if (actions[prop]) return actions[prop];
|
|
81
92
|
return undefined;
|
|
82
93
|
},
|
|
83
94
|
set(_, prop, val) {
|
|
@@ -106,13 +117,12 @@ export function createStore(definition) {
|
|
|
106
117
|
};
|
|
107
118
|
}
|
|
108
119
|
|
|
109
|
-
// --- Simple atom ---
|
|
110
|
-
|
|
111
|
-
//
|
|
112
|
-
// const count = atom(0);
|
|
113
|
-
// count(); // read
|
|
114
|
-
// count.set(5); // write
|
|
115
|
-
|
|
120
|
+
// --- Simple atom --- [DEPRECATED: use signal() directly]
|
|
121
|
+
let _atomWarned = false;
|
|
116
122
|
export function atom(initial) {
|
|
123
|
+
if (!_atomWarned) {
|
|
124
|
+
_atomWarned = true;
|
|
125
|
+
console.warn('[what] atom() is deprecated. Use signal() directly instead.');
|
|
126
|
+
}
|
|
117
127
|
return signal(initial);
|
|
118
128
|
}
|