@braine/quantum-query 1.2.9 → 1.3.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/index.cjs CHANGED
@@ -55,6 +55,9 @@ function createSignal(initialValue, options) {
55
55
  set: (newValue) => {
56
56
  s.value = newValue;
57
57
  },
58
+ update: (fn) => {
59
+ s.value = fn(s.value);
60
+ },
58
61
  subscribe: (fn) => {
59
62
  if (subscriberCount === 0) {
60
63
  options?.onActive?.();
@@ -82,6 +85,9 @@ function computed(fn) {
82
85
  set: () => {
83
86
  throw new Error("[Quantum] Cannot set a computed signal directly.");
84
87
  },
88
+ update: () => {
89
+ throw new Error("[Quantum] Cannot update a computed signal directly.");
90
+ },
85
91
  subscribe: (fn2) => {
86
92
  subscriberCount++;
87
93
  const dispose = (0, import_signals_core.effect)(() => {
package/dist/index.d.cts CHANGED
@@ -10,6 +10,7 @@ import React$1, { ReactNode } from 'react';
10
10
  interface Signal<T> {
11
11
  get: () => T;
12
12
  set: (value: T) => void;
13
+ update: (fn: (current: T) => T) => void;
13
14
  subscribe: (fn: (value: T) => void) => () => void;
14
15
  isWatched: () => boolean;
15
16
  }
package/dist/index.d.ts CHANGED
@@ -10,6 +10,7 @@ import React$1, { ReactNode } from 'react';
10
10
  interface Signal<T> {
11
11
  get: () => T;
12
12
  set: (value: T) => void;
13
+ update: (fn: (current: T) => T) => void;
13
14
  subscribe: (fn: (value: T) => void) => () => void;
14
15
  isWatched: () => boolean;
15
16
  }
package/dist/index.js CHANGED
@@ -14,6 +14,9 @@ function createSignal(initialValue, options) {
14
14
  set: (newValue) => {
15
15
  s.value = newValue;
16
16
  },
17
+ update: (fn) => {
18
+ s.value = fn(s.value);
19
+ },
17
20
  subscribe: (fn) => {
18
21
  if (subscriberCount === 0) {
19
22
  options?.onActive?.();
@@ -41,6 +44,9 @@ function computed(fn) {
41
44
  set: () => {
42
45
  throw new Error("[Quantum] Cannot set a computed signal directly.");
43
46
  },
47
+ update: () => {
48
+ throw new Error("[Quantum] Cannot update a computed signal directly.");
49
+ },
44
50
  subscribe: (fn2) => {
45
51
  subscriberCount++;
46
52
  const dispose = preactEffect(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@braine/quantum-query",
3
- "version": "1.2.9",
3
+ "version": "1.3.0",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "scripts": {