thunderous 0.2.0 → 0.2.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/index.cjs CHANGED
@@ -48,6 +48,8 @@ var setInnerHTML = (element, html2) => {
48
48
 
49
49
  // src/signals.ts
50
50
  var subscriber = null;
51
+ var updateQueue = /* @__PURE__ */ new Set();
52
+ var isBatchingUpdates = false;
51
53
  var createSignal = (initVal) => {
52
54
  const subscribers = /* @__PURE__ */ new Set();
53
55
  let value = initVal;
@@ -58,9 +60,22 @@ var createSignal = (initVal) => {
58
60
  return value;
59
61
  };
60
62
  const setter = (newValue) => {
63
+ const isObject = typeof newValue === "object" && newValue !== null;
64
+ if (!isObject && value === newValue) return;
61
65
  value = newValue;
62
66
  for (const fn of subscribers) {
63
- fn();
67
+ updateQueue.add(fn);
68
+ }
69
+ if (!isBatchingUpdates) {
70
+ isBatchingUpdates = true;
71
+ requestAnimationFrame(() => {
72
+ console.log("next animation frame");
73
+ for (const fn of updateQueue) {
74
+ fn();
75
+ }
76
+ updateQueue.clear();
77
+ isBatchingUpdates = false;
78
+ });
64
79
  }
65
80
  };
66
81
  return [getter, setter];
package/dist/index.js CHANGED
@@ -17,6 +17,8 @@ var setInnerHTML = (element, html2) => {
17
17
 
18
18
  // src/signals.ts
19
19
  var subscriber = null;
20
+ var updateQueue = /* @__PURE__ */ new Set();
21
+ var isBatchingUpdates = false;
20
22
  var createSignal = (initVal) => {
21
23
  const subscribers = /* @__PURE__ */ new Set();
22
24
  let value = initVal;
@@ -27,9 +29,22 @@ var createSignal = (initVal) => {
27
29
  return value;
28
30
  };
29
31
  const setter = (newValue) => {
32
+ const isObject = typeof newValue === "object" && newValue !== null;
33
+ if (!isObject && value === newValue) return;
30
34
  value = newValue;
31
35
  for (const fn of subscribers) {
32
- fn();
36
+ updateQueue.add(fn);
37
+ }
38
+ if (!isBatchingUpdates) {
39
+ isBatchingUpdates = true;
40
+ requestAnimationFrame(() => {
41
+ console.log("next animation frame");
42
+ for (const fn of updateQueue) {
43
+ fn();
44
+ }
45
+ updateQueue.clear();
46
+ isBatchingUpdates = false;
47
+ });
33
48
  }
34
49
  };
35
50
  return [getter, setter];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thunderous",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",