what-core 0.1.1 → 0.2.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/dist/a11y.js +425 -0
- package/dist/animation.js +531 -0
- package/dist/components.js +272 -115
- package/dist/data.js +434 -0
- package/dist/dom.js +635 -424
- package/dist/form.js +441 -0
- package/dist/h.js +191 -138
- package/dist/head.js +59 -42
- package/dist/helpers.js +125 -83
- package/dist/hooks.js +224 -134
- package/dist/index.js +2 -2
- package/dist/reactive.js +150 -107
- package/dist/scheduler.js +241 -0
- package/dist/skeleton.js +363 -0
- package/dist/store.js +113 -55
- package/dist/testing.js +367 -0
- package/dist/what.js +2 -2
- package/index.d.ts +15 -0
- package/package.json +1 -1
- package/src/components.js +93 -0
- package/src/dom.js +47 -15
- package/src/index.js +2 -2
- package/src/store.js +23 -5
package/src/store.js
CHANGED
|
@@ -4,15 +4,32 @@
|
|
|
4
4
|
|
|
5
5
|
import { signal, computed, batch } from './reactive.js';
|
|
6
6
|
|
|
7
|
+
// --- storeComputed ---
|
|
8
|
+
// Marker wrapper to explicitly tag a function as a computed in createStore.
|
|
9
|
+
// Without this, createStore can't distinguish computed(state => ...) from action(item => ...).
|
|
10
|
+
//
|
|
11
|
+
// Usage:
|
|
12
|
+
// const useCounter = createStore({
|
|
13
|
+
// count: 0,
|
|
14
|
+
// doubled: storeComputed(state => state.count * 2),
|
|
15
|
+
// addItem(item) { /* this is an action */ },
|
|
16
|
+
// });
|
|
17
|
+
|
|
18
|
+
export function storeComputed(fn) {
|
|
19
|
+
fn._storeComputed = true;
|
|
20
|
+
return fn;
|
|
21
|
+
}
|
|
22
|
+
|
|
7
23
|
// --- createStore ---
|
|
8
24
|
// Creates a reactive store with actions. Each key becomes a signal.
|
|
9
25
|
//
|
|
10
26
|
// Usage:
|
|
11
27
|
// const useCounter = createStore({
|
|
12
28
|
// count: 0,
|
|
13
|
-
// doubled: (state
|
|
14
|
-
// increment() { this.count++; },
|
|
29
|
+
// doubled: storeComputed(state => state.count * 2), // computed
|
|
30
|
+
// increment() { this.count++; }, // action
|
|
15
31
|
// decrement() { this.count--; },
|
|
32
|
+
// addItem(item) { this.items.push(item); }, // action (not confused with computed)
|
|
16
33
|
// });
|
|
17
34
|
//
|
|
18
35
|
// function Counter() {
|
|
@@ -27,12 +44,13 @@ export function createStore(definition) {
|
|
|
27
44
|
const state = {};
|
|
28
45
|
|
|
29
46
|
// Separate state, computeds, and actions
|
|
47
|
+
// Use explicit _storeComputed marker instead of function.length heuristic
|
|
30
48
|
for (const [key, value] of Object.entries(definition)) {
|
|
31
|
-
if (typeof value === 'function' && value.
|
|
32
|
-
// Computed:
|
|
49
|
+
if (typeof value === 'function' && value._storeComputed) {
|
|
50
|
+
// Computed: explicitly marked with storeComputed()
|
|
33
51
|
computeds[key] = value;
|
|
34
52
|
} else if (typeof value === 'function') {
|
|
35
|
-
// Action:
|
|
53
|
+
// Action: any other function
|
|
36
54
|
actions[key] = value;
|
|
37
55
|
} else {
|
|
38
56
|
// State: initial value
|