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/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
- scheduleRead(() => {
103
- const data = readFn();
104
- if (writeFn) {
105
- scheduleWrite(() => writeFn(data));
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 storeComputed(fn) {
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
- // Even simpler: a single reactive value accessible globally.
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
  }