@vaadin/hilla-react-signals 24.5.0-alpha14 → 24.5.0-alpha15

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.
@@ -30,6 +30,11 @@ export type ServerConnectionConfig = Readonly<{
30
30
  * The name of the signal provider service method.
31
31
  */
32
32
  method: string;
33
+ /**
34
+ * Optional object with method call arguments to be sent to the endpoint
35
+ * method that provides the signal when subscribing to it.
36
+ */
37
+ params?: Record<string, unknown>;
33
38
  }>;
34
39
  /**
35
40
  * A server connection manager.
@@ -72,6 +77,12 @@ export declare abstract class FullStackSignal<T> extends DependencyTrackingSigna
72
77
  */
73
78
  readonly error: import("@preact/signals-core").ReadonlySignal<Error | undefined>;
74
79
  constructor(value: T | undefined, config: ServerConnectionConfig);
80
+ /**
81
+ * Sets the local value of the signal without sending any events to the server
82
+ * @param value - The new value.
83
+ * @internal
84
+ */
85
+ protected setValueLocal(value: T): void;
75
86
  /**
76
87
  * A method to update the server with the new value.
77
88
  *
@@ -1 +1 @@
1
- {"version":3,"file":"FullStackSignal.d.ts","sourceRoot":"","sources":["src/FullStackSignal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE1E,OAAO,EAAoB,MAAM,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAuB,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAInE;;;;;GAKG;AACH,8BAAsB,wBAAwB,CAAC,CAAC,CAAE,SAAQ,MAAM,CAAC,CAAC,CAAC;;IAQjE,SAAS,aAAa,KAAK,EAAE,CAAC,GAAG,SAAS,EAAE,gBAAgB,EAAE,MAAM,IAAI,EAAE,iBAAiB,EAAE,MAAM,IAAI;cAMpF,CAAC,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;cAQtB,CAAC,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;CAO1C;AAED;;;GAGG;AACH,MAAM,M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AC,CAAC,CAAC,CAAC;IAErC;;OAEG;IACH,QAAQ,CAAC,OAAO,yDAAuC;IAEvD;;OAEG;IACH,QAAQ,CAAC,KAAK,mEAAqC;gBASvC,KAAK,EAAE,CAAC,GAAG,SAAS,EAAE,MAAM,EAAE,sBAAsB;IAmBhE;;;;OAIG;IACH,SAAS,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;IAMvC;;;;OAIG;IACH,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI;IAW/C;;;;;OAKG;IACH,SAAS,CAAC,QAAQ,CAAC,CAAC,sBAAsB,CAAC,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI;CAgBxE"}
@@ -40,11 +40,12 @@ class ServerConnection {
40
40
  return this.#subscription;
41
41
  }
42
42
  connect() {
43
- const { client, endpoint, method } = this.#config;
43
+ const { client, endpoint, method, params } = this.#config;
44
44
  this.#subscription ??= client.subscribe(ENDPOINT, "subscribe", {
45
45
  providerEndpoint: endpoint,
46
46
  providerMethod: method,
47
- clientSignalId: this.#id
47
+ clientSignalId: this.#id,
48
+ params
48
49
  });
49
50
  return this.#subscription;
50
51
  }
@@ -100,6 +101,16 @@ class FullStackSignal extends DependencyTrackingSignal {
100
101
  });
101
102
  this.#paused = false;
102
103
  }
104
+ /**
105
+ * Sets the local value of the signal without sending any events to the server
106
+ * @param value - The new value.
107
+ * @internal
108
+ */
109
+ setValueLocal(value) {
110
+ this.#paused = true;
111
+ this.value = value;
112
+ this.#paused = false;
113
+ }
103
114
  /**
104
115
  * A method to update the server with the new value.
105
116
  *
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["src/FullStackSignal.ts"],
4
- "sourcesContent": ["import type { ConnectClient, Subscription } from '@vaadin/hilla-frontend';\nimport { nanoid } from 'nanoid';\nimport { computed, signal, Signal } from './core.js';\nimport { createSetStateEvent, type StateEvent } from './events.js';\n\nconst ENDPOINT = 'SignalsHandler';\n\n/**\n * An abstraction of a signal that tracks the number of subscribers, and calls\n * the provided `onSubscribe` and `onUnsubscribe` callbacks for the first\n * subscription and the last unsubscription, respectively.\n * @internal\n */\nexport abstract class DependencyTrackingSignal<T> extends Signal<T> {\n readonly #onFirstSubscribe: () => void;\n readonly #onLastUnsubscribe: () => void;\n\n // -1 means to ignore the first subscription that is created internally in the\n // FullStackSignal constructor.\n #subscribeCount = -1;\n\n protected constructor(value: T | undefined, onFirstSubscribe: () => void, onLastUnsubscribe: () => void) {\n super(value);\n this.#onFirstSubscribe = onFirstSubscribe;\n this.#onLastUnsubscribe = onLastUnsubscribe;\n }\n\n protected override S(node: unknown): void {\n super.S(node);\n if (this.#subscribeCount === 0) {\n this.#onFirstSubscribe();\n }\n this.#subscribeCount += 1;\n }\n\n protected override U(node: unknown): void {\n super.U(node);\n this.#subscribeCount -= 1;\n if (this.#subscribeCount === 0) {\n this.#onLastUnsubscribe();\n }\n }\n}\n\n/**\n * An object that describes a data object to connect to the signal provider\n * service.\n */\nexport type ServerConnectionConfig = Readonly<{\n /**\n * The client instance to be used for communication.\n */\n client: ConnectClient;\n\n /**\n * The name of the signal provider service endpoint.\n */\n endpoint: string;\n\n /**\n * The name of the signal provider service method.\n */\n method: string;\n}>;\n\n/**\n * A server connection manager.\n */\nclass ServerConnection<T> {\n readonly #id: string;\n readonly #config: ServerConnectionConfig;\n #subscription?: Subscription<StateEvent<T>>;\n\n constructor(id: string, config: ServerConnectionConfig) {\n this.#config = config;\n this.#id = id;\n }\n\n get subscription() {\n return this.#subscription;\n }\n\n connect() {\n const { client, endpoint, method } = this.#config;\n\n this.#subscription ??= client.subscribe(ENDPOINT, 'subscribe', {\n providerEndpoint: endpoint,\n providerMethod: method,\n clientSignalId: this.#id,\n });\n\n return this.#subscription;\n }\n\n async update(event: StateEvent<T>): Promise<void> {\n await this.#config.client.call(ENDPOINT, 'update', {\n clientSignalId: this.#id,\n event,\n });\n }\n\n disconnect() {\n this.#subscription?.cancel();\n this.#subscription = undefined;\n }\n}\n\nexport const $update = Symbol('update');\nexport const $processServerResponse = Symbol('processServerResponse');\n\n/**\n * A signal that holds a shared value. Each change to the value is propagated to\n * the server-side signal provider. At the same time, each change received from\n * the server-side signal provider is propagated to the local signal and it's\n * subscribers.\n *\n * @internal\n */\nexport abstract class FullStackSignal<T> extends DependencyTrackingSignal<T> {\n /**\n * The unique identifier of the signal necessary to communicate with the\n * server.\n */\n readonly id = nanoid();\n\n /**\n * The server connection manager.\n */\n readonly server: ServerConnection<T>;\n\n /**\n * Defines whether the signal is currently awaits a server-side response.\n */\n readonly pending = computed(() => this.#pending.value);\n\n /**\n * Defines whether the signal has an error.\n */\n readonly error = computed(() => this.#error.value);\n\n readonly #pending = signal(false);\n readonly #error = signal<Error | undefined>(undefined);\n\n // Paused at the very start to prevent the signal from sending the initial\n // value to the server.\n #paused = true;\n\n constructor(value: T | undefined, config: ServerConnectionConfig) {\n super(\n value,\n () => this.#connect(),\n () => this.#disconnect(),\n );\n this.server = new ServerConnection(this.id, config);\n\n this.subscribe((v) => {\n if (!this.#paused) {\n this.#pending.value = true;\n this.#error.value = undefined;\n this[$update](createSetStateEvent(v));\n }\n });\n\n this.#paused = false;\n }\n\n /**\n * A method to update the server with the new value.\n *\n * @param event - The event to update the server with.\n */\n protected [$update](event: StateEvent<T>): void {\n this.server\n .update(event)\n .catch((error: unknown) => {\n this.#error.value = error instanceof Error ? error : new Error(String(error));\n })\n .finally(() => {\n this.#pending.value = false;\n });\n }\n\n /**\n * A method with to process the server response. The implementation is\n * specific for each signal type.\n *\n * @param event - The server response event.\n */\n protected abstract [$processServerResponse](event: StateEvent<T>): void;\n\n #connect() {\n this.server.connect().onNext((event: StateEvent<T>) => {\n this.#paused = true;\n this[$processServerResponse](event);\n this.#paused = false;\n });\n }\n\n #disconnect() {\n if (this.server.subscription === undefined) {\n return;\n }\n this.server.disconnect();\n }\n}\n"],
5
- "mappings":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AAAA,EAEA,cAAc;AACZ,QAAI,KAAK,OAAO,iBAAiB,QAAW;AAC1C;AAAA,IACF;AACA,SAAK,OAAO,WAAW;AAAA,EACzB;AACF;",
4
+ "sourcesContent": ["import type { ConnectClient, Subscription } from '@vaadin/hilla-frontend';\nimport { nanoid } from 'nanoid';\nimport { computed, signal, Signal } from './core.js';\nimport { createSetStateEvent, type StateEvent } from './events.js';\n\nconst ENDPOINT = 'SignalsHandler';\n\n/**\n * An abstraction of a signal that tracks the number of subscribers, and calls\n * the provided `onSubscribe` and `onUnsubscribe` callbacks for the first\n * subscription and the last unsubscription, respectively.\n * @internal\n */\nexport abstract class DependencyTrackingSignal<T> extends Signal<T> {\n readonly #onFirstSubscribe: () => void;\n readonly #onLastUnsubscribe: () => void;\n\n // -1 means to ignore the first subscription that is created internally in the\n // FullStackSignal constructor.\n #subscribeCount = -1;\n\n protected constructor(value: T | undefined, onFirstSubscribe: () => void, onLastUnsubscribe: () => void) {\n super(value);\n this.#onFirstSubscribe = onFirstSubscribe;\n this.#onLastUnsubscribe = onLastUnsubscribe;\n }\n\n protected override S(node: unknown): void {\n super.S(node);\n if (this.#subscribeCount === 0) {\n this.#onFirstSubscribe();\n }\n this.#subscribeCount += 1;\n }\n\n protected override U(node: unknown): void {\n super.U(node);\n this.#subscribeCount -= 1;\n if (this.#subscribeCount === 0) {\n this.#onLastUnsubscribe();\n }\n }\n}\n\n/**\n * An object that describes a data object to connect to the signal provider\n * service.\n */\nexport type ServerConnectionConfig = Readonly<{\n /**\n * The client instance to be used for communication.\n */\n client: ConnectClient;\n\n /**\n * The name of the signal provider service endpoint.\n */\n endpoint: string;\n\n /**\n * The name of the signal provider service method.\n */\n method: string;\n\n /**\n * Optional object with method call arguments to be sent to the endpoint\n * method that provides the signal when subscribing to it.\n */\n params?: Record<string, unknown>;\n}>;\n\n/**\n * A server connection manager.\n */\nclass ServerConnection<T> {\n readonly #id: string;\n readonly #config: ServerConnectionConfig;\n #subscription?: Subscription<StateEvent<T>>;\n\n constructor(id: string, config: ServerConnectionConfig) {\n this.#config = config;\n this.#id = id;\n }\n\n get subscription() {\n return this.#subscription;\n }\n\n connect() {\n const { client, endpoint, method, params } = this.#config;\n\n this.#subscription ??= client.subscribe(ENDPOINT, 'subscribe', {\n providerEndpoint: endpoint,\n providerMethod: method,\n clientSignalId: this.#id,\n params,\n });\n\n return this.#subscription;\n }\n\n async update(event: StateEvent<T>): Promise<void> {\n await this.#config.client.call(ENDPOINT, 'update', {\n clientSignalId: this.#id,\n event,\n });\n }\n\n disconnect() {\n this.#subscription?.cancel();\n this.#subscription = undefined;\n }\n}\n\nexport const $update = Symbol('update');\nexport const $processServerResponse = Symbol('processServerResponse');\n\n/**\n * A signal that holds a shared value. Each change to the value is propagated to\n * the server-side signal provider. At the same time, each change received from\n * the server-side signal provider is propagated to the local signal and it's\n * subscribers.\n *\n * @internal\n */\nexport abstract class FullStackSignal<T> extends DependencyTrackingSignal<T> {\n /**\n * The unique identifier of the signal necessary to communicate with the\n * server.\n */\n readonly id = nanoid();\n\n /**\n * The server connection manager.\n */\n readonly server: ServerConnection<T>;\n\n /**\n * Defines whether the signal is currently awaits a server-side response.\n */\n readonly pending = computed(() => this.#pending.value);\n\n /**\n * Defines whether the signal has an error.\n */\n readonly error = computed(() => this.#error.value);\n\n readonly #pending = signal(false);\n readonly #error = signal<Error | undefined>(undefined);\n\n // Paused at the very start to prevent the signal from sending the initial\n // value to the server.\n #paused = true;\n\n constructor(value: T | undefined, config: ServerConnectionConfig) {\n super(\n value,\n () => this.#connect(),\n () => this.#disconnect(),\n );\n this.server = new ServerConnection(this.id, config);\n\n this.subscribe((v) => {\n if (!this.#paused) {\n this.#pending.value = true;\n this.#error.value = undefined;\n this[$update](createSetStateEvent(v));\n }\n });\n\n this.#paused = false;\n }\n\n /**\n * Sets the local value of the signal without sending any events to the server\n * @param value - The new value.\n * @internal\n */\n protected setValueLocal(value: T): void {\n this.#paused = true;\n this.value = value;\n this.#paused = false;\n }\n\n /**\n * A method to update the server with the new value.\n *\n * @param event - The event to update the server with.\n */\n protected [$update](event: StateEvent<T>): void {\n this.server\n .update(event)\n .catch((error: unknown) => {\n this.#error.value = error instanceof Error ? error : new Error(String(error));\n })\n .finally(() => {\n this.#pending.value = false;\n });\n }\n\n /**\n * A method with to process the server response. The implementation is\n * specific for each signal type.\n *\n * @param event - The server response event.\n */\n protected abstract [$processServerResponse](event: StateEvent<T>): void;\n\n #connect() {\n this.server.connect().onNext((event: StateEvent<T>) => {\n this.#paused = true;\n this[$processServerResponse](event);\n this.#paused = false;\n });\n }\n\n #disconnect() {\n if (this.server.subscription === undefined) {\n return;\n }\n this.server.disconnect();\n }\n}\n"],
5
+ "mappings": "AACA,SAAS,cAAc;AACvB,SAAS,UAAU,QAAQ,cAAc;AACzC,SAAS,2BAA4C;AAErD,MAAM,WAAW;AAQV,MAAe,iCAAoC,OAAU;AAAA,EACzD;AAAA,EACA;AAAA;AAAA;AAAA,EAIT,kBAAkB;AAAA,EAER,YAAY,OAAsB,kBAA8B,mBAA+B;AACvG,UAAM,KAAK;AACX,SAAK,oBAAoB;AACzB,SAAK,qBAAqB;AAAA,EAC5B;AAAA,EAEmB,EAAE,MAAqB;AACxC,UAAM,EAAE,IAAI;AACZ,QAAI,KAAK,oBAAoB,GAAG;AAC9B,WAAK,kBAAkB;AAAA,IACzB;AACA,SAAK,mBAAmB;AAAA,EAC1B;AAAA,EAEmB,EAAE,MAAqB;AACxC,UAAM,EAAE,IAAI;AACZ,SAAK,mBAAmB;AACxB,QAAI,KAAK,oBAAoB,GAAG;AAC9B,WAAK,mBAAmB;AAAA,IAC1B;AAAA,EACF;AACF;AAgCA,MAAM,iBAAoB;AAAA,EACf;AAAA,EACA;AAAA,EACT;AAAA,EAEA,YAAY,IAAY,QAAgC;AACtD,SAAK,UAAU;AACf,SAAK,MAAM;AAAA,EACb;AAAA,EAEA,IAAI,eAAe;AACjB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,UAAU;AACR,UAAM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AA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU,cAAc,OAAgB;AACtC,SAAK,UAAU;AACf,SAAK,QAAQ;AACb,SAAK,UAAU;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,CAAW,OAAO,EAAE,OAA4B;AAC9C,SAAK,OACF,OAAO,KAAK,EACZ,MAAM,CAAC,UAAmB;AACzB,WAAK,OAAO,QAAQ,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;AAAA,IAC9E,CAAC,EACA,QAAQ,MAAM;AACb,WAAK,SAAS,QAAQ;AAAA,IACxB,CAAC;AAAA,EACL;AAAA,EAUA,WAAW;AACT,SAAK,OAAO,QAAQ,EAAE,OAAO,CAAC,UAAyB;AACrD,WAAK,UAAU;AACf,WAAK,sBAAsB,EAAE,KAAK;AAClC,WAAK,UAAU;AAAA,IACjB,CAAC;AAAA,EACH;AAAA,EAEA,cAAc;AACZ,QAAI,KAAK,OAAO,iBAAiB,QAAW;AAC1C;AAAA,IACF;AACA,SAAK,OAAO,WAAW;AAAA,EACzB;AACF;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,40 @@
1
+ import { ValueSignal } from './ValueSignal.js';
2
+ /**
3
+ * A signal that holds a number value. The underlying
4
+ * value of this signal is stored and updated as a
5
+ * shared value on the server.
6
+ *
7
+ * After obtaining the NumberSignal instance from
8
+ * a server-side service that returns one, the value
9
+ * can be updated using the `value` property,
10
+ * and it can be read with or without the
11
+ * `value` property (similar to a normal signal):
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * const counter = CounterService.counter();
16
+ *
17
+ * return (
18
+ * <Button onClick={() => counter.incrementBy(1)}>
19
+ * Click count: { counter }
20
+ * </Button>
21
+ * <Button onClick={() => counter.value = 0}>Reset</Button>
22
+ * );
23
+ * ```
24
+ */
25
+ export declare class NumberSignal extends ValueSignal<number> {
26
+ /**
27
+ * Increments the value by the specified delta. The delta can be negative to
28
+ * decrease the value.
29
+ *
30
+ * This method differs from using the `++` or `+=` operators directly on the
31
+ * signal value. It performs an atomic operation to prevent conflicts from
32
+ * concurrent changes, ensuring that other users' modifications are not
33
+ * accidentally overwritten.
34
+ *
35
+ * @param delta - The delta to increment the value by. The delta can be
36
+ * negative.
37
+ */
38
+ incrementBy(delta: number): void;
39
+ }
40
+ //# sourceMappingURL=NumberSignal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NumberSignal.d.ts","sourceRoot":"","sources":["src/NumberSignal.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,YAAa,SAAQ,WAAW,CAAC,MAAM,CAAC;IACnD;;;;;;;;;;;OAWG;IACH,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;CAQjC"}
@@ -0,0 +1,29 @@
1
+ import { createIncrementStateEvent } from "./events.js";
2
+ import { $update } from "./FullStackSignal.js";
3
+ import { ValueSignal } from "./ValueSignal.js";
4
+ class NumberSignal extends ValueSignal {
5
+ /**
6
+ * Increments the value by the specified delta. The delta can be negative to
7
+ * decrease the value.
8
+ *
9
+ * This method differs from using the `++` or `+=` operators directly on the
10
+ * signal value. It performs an atomic operation to prevent conflicts from
11
+ * concurrent changes, ensuring that other users' modifications are not
12
+ * accidentally overwritten.
13
+ *
14
+ * @param delta - The delta to increment the value by. The delta can be
15
+ * negative.
16
+ */
17
+ incrementBy(delta) {
18
+ if (delta === 0) {
19
+ return;
20
+ }
21
+ this.setValueLocal(this.value + delta);
22
+ const event = createIncrementStateEvent(delta);
23
+ this[$update](event);
24
+ }
25
+ }
26
+ export {
27
+ NumberSignal
28
+ };
29
+ //# sourceMappingURL=NumberSignal.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/NumberSignal.ts"],
4
+ "sourcesContent": ["import { createIncrementStateEvent } from './events.js';\nimport { $update } from './FullStackSignal.js';\nimport { ValueSignal } from './ValueSignal.js';\n\n/**\n * A signal that holds a number value. The underlying\n * value of this signal is stored and updated as a\n * shared value on the server.\n *\n * After obtaining the NumberSignal instance from\n * a server-side service that returns one, the value\n * can be updated using the `value` property,\n * and it can be read with or without the\n * `value` property (similar to a normal signal):\n *\n * @example\n * ```tsx\n * const counter = CounterService.counter();\n *\n * return (\n * <Button onClick={() => counter.incrementBy(1)}>\n * Click count: { counter }\n * </Button>\n * <Button onClick={() => counter.value = 0}>Reset</Button>\n * );\n * ```\n */\nexport class NumberSignal extends ValueSignal<number> {\n /**\n * Increments the value by the specified delta. The delta can be negative to\n * decrease the value.\n *\n * This method differs from using the `++` or `+=` operators directly on the\n * signal value. It performs an atomic operation to prevent conflicts from\n * concurrent changes, ensuring that other users' modifications are not\n * accidentally overwritten.\n *\n * @param delta - The delta to increment the value by. The delta can be\n * negative.\n */\n incrementBy(delta: number): void {\n if (delta === 0) {\n return;\n }\n this.setValueLocal(this.value + delta);\n const event = createIncrementStateEvent(delta);\n this[$update](event);\n }\n}\n"],
5
+ "mappings": "AAAA,SAAS,iCAAiC;AAC1C,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAyBrB,MAAM,qBAAqB,YAAoB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAapD,YAAY,OAAqB;AAC/B,QAAI,UAAU,GAAG;AACf;AAAA,IACF;AACA,SAAK,cAAc,KAAK,QAAQ,KAAK;AACrC,UAAM,QAAQ,0BAA0B,KAAK;AAC7C,SAAK,OAAO,EAAE,KAAK;AAAA,EACrB;AACF;",
6
+ "names": []
7
+ }
package/events.d.ts CHANGED
@@ -23,9 +23,11 @@ export type ReplaceStateEvent<T> = CreateStateEventType<T, 'replace', {
23
23
  expected: T;
24
24
  }>;
25
25
  export declare function createReplaceStateEvent<T>(expected: T, value: T): ReplaceStateEvent<T>;
26
+ export type IncrementStateEvent = CreateStateEventType<number, 'increment'>;
27
+ export declare function createIncrementStateEvent(delta: number): IncrementStateEvent;
26
28
  /**
27
29
  * An object that describes the change of the signal state.
28
30
  */
29
- export type StateEvent<T> = RejectStateEvent | ReplaceStateEvent<T> | SetStateEvent<T> | SnapshotStateEvent<T>;
31
+ export type StateEvent<T> = IncrementStateEvent | RejectStateEvent | ReplaceStateEvent<T> | SetStateEvent<T> | SnapshotStateEvent<T>;
30
32
  export {};
31
33
  //# sourceMappingURL=events.d.ts.map
package/events.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["src/events.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1C;;GAEG;AACH,KAAK,oBAAoB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,QAAQ,CACjH,QAAQ,CAAC;IACP,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,CAAC,CAAC;IACR,KAAK,EAAE,CAAC,CAAC;CACV,CAAC,GACA,QAAQ,CAAC,CAAC,CAAC,CACd,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,oBAAoB,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;AAExE,MAAM,MAAM,gBAAgB,GAAG,oBAAoB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AAErE;;;GAGG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,oBAAoB,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AAE9D,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAMjE;AAED,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,oBAAoB,CAAC,CAAC,EA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BAAoB,CAAC,CAAC,EAAE,SAAS,EAAE;IAAE,QAAQ,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC;AAEvF,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAOtF;AAED,MAAM,MAAM,mBAAmB,GAAG,oBAAoB,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAE5E,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,mBAAmB,CAM5E;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IACpB,mBAAmB,GACnB,gBAAgB,GAChB,iBAAiB,CAAC,CAAC,CAAC,GACpB,aAAa,CAAC,CAAC,CAAC,GAChB,kBAAkB,CAAC,CAAC,CAAC,CAAC"}
package/events.js CHANGED
@@ -14,7 +14,15 @@ function createReplaceStateEvent(expected, value) {
14
14
  expected
15
15
  };
16
16
  }
17
+ function createIncrementStateEvent(delta) {
18
+ return {
19
+ id: nanoid(),
20
+ type: "increment",
21
+ value: delta
22
+ };
23
+ }
17
24
  export {
25
+ createIncrementStateEvent,
18
26
  createReplaceStateEvent,
19
27
  createSetStateEvent
20
28
  };
package/events.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["src/events.ts"],
4
- "sourcesContent": ["import { nanoid } from 'nanoid';\nimport type { Simplify } from 'type-fest';\n\n/**\n * Creates a new state event type.\n */\ntype CreateStateEventType<V, T extends string, C extends Record<string, unknown> = Record<never, never>> = Simplify<\n Readonly<{\n id: string;\n type: T;\n value: V;\n }> &\n Readonly<C>\n>;\n\n/**\n * A state event received from the server describing the current state of the\n * signal.\n */\nexport type SnapshotStateEvent<T> = CreateStateEventType<T, 'snapshot'>;\n\nexport type RejectStateEvent = CreateStateEventType<never, 'reject'>;\n\n/**\n * A state event defines a new value of the signal shared with the server. The\n *\n */\nexport type SetStateEvent<T> = CreateStateEventType<T, 'set'>;\n\nexport function createSetStateEvent<T>(value: T): SetStateEvent<T> {\n return {\n id: nanoid(),\n type: 'set',\n value,\n };\n}\n\nexport type ReplaceStateEvent<T> = CreateStateEventType<T, 'replace', { expected: T }>;\n\nexport function createReplaceStateEvent<T>(expected: T, value: T): ReplaceStateEvent<T> {\n return {\n id: nanoid(),\n type: 'replace',\n value,\n expected,\n };\n}\n\n/**\n * An object that describes the change of the signal state.\n */\nexport type StateEvent<T> = RejectStateEvent | ReplaceStateEvent<T> | SetStateEvent<T> | SnapshotStateEvent<T>;\n"],
5
- "mappings": "AAAA,SAAS,cAAc;AA6BhB,SAAS,oBAAuB,OAA4B;AACjE,SAAO;AAAA,IACL,IAAI,OAAO;AAAA,IACX,MAAM;AAAA,IACN;AAAA,EACF;AACF;AAIO,SAAS,wBAA2B,UAAa,OAAgC;AACtF,SAAO;AAAA,IACL,IAAI,OAAO;AAAA,IACX,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import { nanoid } from 'nanoid';\nimport type { Simplify } from 'type-fest';\n\n/**\n * Creates a new state event type.\n */\ntype CreateStateEventType<V, T extends string, C extends Record<string, unknown> = Record<never, never>> = Simplify<\n Readonly<{\n id: string;\n type: T;\n value: V;\n }> &\n Readonly<C>\n>;\n\n/**\n * A state event received from the server describing the current state of the\n * signal.\n */\nexport type SnapshotStateEvent<T> = CreateStateEventType<T, 'snapshot'>;\n\nexport type RejectStateEvent = CreateStateEventType<never, 'reject'>;\n\n/**\n * A state event defines a new value of the signal shared with the server. The\n *\n */\nexport type SetStateEvent<T> = CreateStateEventType<T, 'set'>;\n\nexport function createSetStateEvent<T>(value: T): SetStateEvent<T> {\n return {\n id: nanoid(),\n type: 'set',\n value,\n };\n}\n\nexport type ReplaceStateEvent<T> = CreateStateEventType<T, 'replace', { expected: T }>;\n\nexport function createReplaceStateEvent<T>(expected: T, value: T): ReplaceStateEvent<T> {\n return {\n id: nanoid(),\n type: 'replace',\n value,\n expected,\n };\n}\n\nexport type IncrementStateEvent = CreateStateEventType<number, 'increment'>;\n\nexport function createIncrementStateEvent(delta: number): IncrementStateEvent {\n return {\n id: nanoid(),\n type: 'increment',\n value: delta,\n };\n}\n\n/**\n * An object that describes the change of the signal state.\n */\nexport type StateEvent<T> =\n | IncrementStateEvent\n | RejectStateEvent\n | ReplaceStateEvent<T>\n | SetStateEvent<T>\n | SnapshotStateEvent<T>;\n"],
5
+ "mappings": "AAAA,SAAS,cAAc;AA6BhB,SAAS,oBAAuB,OAA4B;AACjE,SAAO;AAAA,IACL,IAAI,OAAO;AAAA,IACX,MAAM;AAAA,IACN;AAAA,EACF;AACF;AAIO,SAAS,wBAA2B,UAAa,OAAgC;AACtF,SAAO;AAAA,IACL,IAAI,OAAO;AAAA,IACX,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACF;AACF;AAIO,SAAS,0BAA0B,OAAoC;AAC5E,SAAO;AAAA,IACL,IAAI,OAAO;AAAA,IACX,MAAM;AAAA,IACN,OAAO;AAAA,EACT;AACF;",
6
6
  "names": []
7
7
  }
package/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import './polyfills.js';
2
2
  export * from './core.js';
3
- export { NumberSignal } from './Signals.js';
3
+ export { NumberSignal } from './NumberSignal.js';
4
4
  export { ValueSignal } from './ValueSignal.js';
5
5
  export type { OperationSubscription } from './ValueSignal.js';
6
6
  export { FullStackSignal } from './FullStackSignal.js';
package/index.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AACA,OAAO,gBAAgB,CAAC;AAGxB,cAAc,WAAW,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,YAAY,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AACA,OAAO,gBAAgB,CAAC;AAGxB,cAAc,WAAW,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,YAAY,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import "./polyfills.js";
2
2
  export * from "./core.js";
3
- import { NumberSignal } from "./Signals.js";
3
+ import { NumberSignal } from "./NumberSignal.js";
4
4
  import { ValueSignal } from "./ValueSignal.js";
5
5
  import { FullStackSignal } from "./FullStackSignal.js";
6
6
  export {
package/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["src/index.ts"],
4
- "sourcesContent": ["// eslint-disable-next-line import/no-unassigned-import\nimport './polyfills.js';\n\n// eslint-disable-next-line import/export\nexport * from './core.js';\nexport { NumberSignal } from './Signals.js';\nexport { ValueSignal } from './ValueSignal.js';\nexport type { OperationSubscription } from './ValueSignal.js';\nexport { FullStackSignal } from './FullStackSignal.js';\n"],
4
+ "sourcesContent": ["// eslint-disable-next-line import/no-unassigned-import\nimport './polyfills.js';\n\n// eslint-disable-next-line import/export\nexport * from './core.js';\nexport { NumberSignal } from './NumberSignal.js';\nexport { ValueSignal } from './ValueSignal.js';\nexport type { OperationSubscription } from './ValueSignal.js';\nexport { FullStackSignal } from './FullStackSignal.js';\n"],
5
5
  "mappings": "AACA,OAAO;AAGP,cAAc;AACd,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAE5B,SAAS,uBAAuB;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/hilla-react-signals",
3
- "version": "24.5.0-alpha14",
3
+ "version": "24.5.0-alpha15",
4
4
  "description": "Signals for Hilla React",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -47,12 +47,12 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "@preact/signals-react": "^2.0.0",
50
- "@vaadin/hilla-frontend": "24.5.0-alpha14",
50
+ "@vaadin/hilla-frontend": "24.5.0-alpha15",
51
51
  "nanoid": "^5.0.7"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "react": "^18",
55
- "react-router-dom": "^6"
55
+ "react-router-dom": "^6.26.2"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@esm-bundle/chai": "^4.3.4-fix.0",
@@ -74,6 +74,6 @@
74
74
  "karma-viewport": "^1.0.9",
75
75
  "sinon": "^16.0.0",
76
76
  "sinon-chai": "^3.7.0",
77
- "typescript": "5.5.2"
77
+ "typescript": "5.6.2"
78
78
  }
79
79
  }
package/Signals.d.ts DELETED
@@ -1,84 +0,0 @@
1
- import { type OperationSubscription, ValueSignal } from './ValueSignal.js';
2
- /**
3
- * A signal that holds a number value. The underlying
4
- * value of this signal is stored and updated as a
5
- * shared value on the server.
6
- *
7
- * After obtaining the NumberSignal instance from
8
- * a server-side service that returns one, the value
9
- * can be updated using the `value` property,
10
- * and it can be read with or without the
11
- * `value` property (similar to a normal signal):
12
- *
13
- * @example
14
- * ```tsx
15
- * const counter = CounterService.counter();
16
- *
17
- * return (
18
- * <Button onClick={() => counter++)}>
19
- * Click count: { counter }
20
- * </Button>
21
- * <Button onClick={() => counter.value = 0}>Reset</Button>
22
- * );
23
- * ```
24
- */
25
- export declare class NumberSignal extends ValueSignal<number> {
26
- /**
27
- * Increments the value by the specified delta. The delta can be negative to
28
- * decrease the value. If no delta is provided, the value increases by 1.
29
- *
30
- * This method differs from using the `++` or `+=` operators directly on the
31
- * signal instance. It performs an atomic operation to prevent conflicts from
32
- * concurrent changes, ensuring that other users' modifications are not
33
- * accidentally overwritten.
34
- *
35
- * By default, if there are concurrent changes on the server, this operation
36
- * will keep retrying until it succeeds. The returned `OperationSubscription`
37
- * can be used to cancel the operation, if needed.
38
- * To disable automatic retries, set `retryOnFailure` to `false`. Note that
39
- * when `retryOnFailure` is `false`, the returned `OperationSubscription` will
40
- * not be cancellable.
41
- *
42
- * @remarks
43
- * **IMPORTANT:** please note that if the operation has already succeeded on
44
- * the server, calling `cancel` will not prevent or undo the operation.The
45
- * `cancel` method only stops further retry attempts if a previous attempt was
46
- * rejected by the server.
47
- *
48
- * @param delta - The delta to increment the value by. The delta can be
49
- * negative. Defaults to 1.
50
- * @param retryOnFailure - Whether to retry the operation in case of a
51
- * concurrent value change on the server or not. Defaults to `true`.
52
- *
53
- * @returns An object that can be used to cancel the operation.
54
- */
55
- increment(delta?: number, retryOnFailure?: boolean): OperationSubscription;
56
- /**
57
- * Adds the provided delta to the value. The delta can be negative to perform
58
- * a subtraction.
59
- * This operation does not retry in case failure due to concurrent value
60
- * changes from other clients have already applied to the shared value on the
61
- * server. If you want the operation to be retried until it succeeds, use the
62
- * overload with retry functionality.
63
- *
64
- * @param delta - The delta to add to the value. The delta can be negative to
65
- * perform a subtraction.
66
- * @see {@link NumberSignal.add|add(delta: number, retryOnFailure: boolean)}
67
- */
68
- add(delta: number): void;
69
- /**
70
- * Adds the provided delta to the value. The delta can be negative to perform
71
- * a subtraction.
72
- * If `true` passed to the `retryOnFailure` parameter, the operation is
73
- * retried in case of failures due to concurrent value changes on the server
74
- * until it succeeds. Note that the returned operation subscription can be
75
- * used to cancel the operation.
76
- *
77
- * @param delta - The delta to add to the value. The delta can be negative.
78
- * @param retryOnFailure - Whether to retry the operation in case of failures
79
- * due to concurrent value changes on the server or not.
80
- * @returns An operation subscription that can be canceled.
81
- */
82
- add(delta: number, retryOnFailure: boolean): OperationSubscription;
83
- }
84
- //# sourceMappingURL=Signals.d.ts.map
package/Signals.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"Signals.d.ts","sourceRoot":"","sources":["src/Signals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,qBAAqB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE3E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,YAAa,SAAQ,WAAW,CAAC,MAAM,CAAC;IACnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,SAAS,CAAC,KAAK,GAAE,MAAU,EAAE,cAAc,GAAE,OAAc,GAAG,qBAAqB;IAanF;;;;;;;;;;;OAWG;IACH,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAExB;;;;;;;;;;;;OAYG;IACH,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,GAAG,qBAAqB;CAanE"}
package/Signals.js DELETED
@@ -1,59 +0,0 @@
1
- import { ValueSignal } from "./ValueSignal.js";
2
- class NumberSignal extends ValueSignal {
3
- /**
4
- * Increments the value by the specified delta. The delta can be negative to
5
- * decrease the value. If no delta is provided, the value increases by 1.
6
- *
7
- * This method differs from using the `++` or `+=` operators directly on the
8
- * signal instance. It performs an atomic operation to prevent conflicts from
9
- * concurrent changes, ensuring that other users' modifications are not
10
- * accidentally overwritten.
11
- *
12
- * By default, if there are concurrent changes on the server, this operation
13
- * will keep retrying until it succeeds. The returned `OperationSubscription`
14
- * can be used to cancel the operation, if needed.
15
- * To disable automatic retries, set `retryOnFailure` to `false`. Note that
16
- * when `retryOnFailure` is `false`, the returned `OperationSubscription` will
17
- * not be cancellable.
18
- *
19
- * @remarks
20
- * **IMPORTANT:** please note that if the operation has already succeeded on
21
- * the server, calling `cancel` will not prevent or undo the operation.The
22
- * `cancel` method only stops further retry attempts if a previous attempt was
23
- * rejected by the server.
24
- *
25
- * @param delta - The delta to increment the value by. The delta can be
26
- * negative. Defaults to 1.
27
- * @param retryOnFailure - Whether to retry the operation in case of a
28
- * concurrent value change on the server or not. Defaults to `true`.
29
- *
30
- * @returns An object that can be used to cancel the operation.
31
- */
32
- increment(delta = 1, retryOnFailure = true) {
33
- const noopCancelSubscription = { cancel: () => {
34
- } };
35
- if (delta === 0) {
36
- return noopCancelSubscription;
37
- }
38
- if (!retryOnFailure) {
39
- const expected = this.value;
40
- this.replace(expected, expected + delta);
41
- return noopCancelSubscription;
42
- }
43
- return this.update((value) => value + delta);
44
- }
45
- add(delta, retryOnFailure) {
46
- if (delta !== 0) {
47
- if (retryOnFailure) {
48
- return this.increment(delta, retryOnFailure);
49
- }
50
- const expected = this.value;
51
- this.replace(expected, expected + delta);
52
- }
53
- return;
54
- }
55
- }
56
- export {
57
- NumberSignal
58
- };
59
- //# sourceMappingURL=Signals.js.map
package/Signals.js.map DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["src/Signals.ts"],
4
- "sourcesContent": ["import { type OperationSubscription, ValueSignal } from './ValueSignal.js';\n\n/**\n * A signal that holds a number value. The underlying\n * value of this signal is stored and updated as a\n * shared value on the server.\n *\n * After obtaining the NumberSignal instance from\n * a server-side service that returns one, the value\n * can be updated using the `value` property,\n * and it can be read with or without the\n * `value` property (similar to a normal signal):\n *\n * @example\n * ```tsx\n * const counter = CounterService.counter();\n *\n * return (\n * <Button onClick={() => counter++)}>\n * Click count: { counter }\n * </Button>\n * <Button onClick={() => counter.value = 0}>Reset</Button>\n * );\n * ```\n */\nexport class NumberSignal extends ValueSignal<number> {\n /**\n * Increments the value by the specified delta. The delta can be negative to\n * decrease the value. If no delta is provided, the value increases by 1.\n *\n * This method differs from using the `++` or `+=` operators directly on the\n * signal instance. It performs an atomic operation to prevent conflicts from\n * concurrent changes, ensuring that other users' modifications are not\n * accidentally overwritten.\n *\n * By default, if there are concurrent changes on the server, this operation\n * will keep retrying until it succeeds. The returned `OperationSubscription`\n * can be used to cancel the operation, if needed.\n * To disable automatic retries, set `retryOnFailure` to `false`. Note that\n * when `retryOnFailure` is `false`, the returned `OperationSubscription` will\n * not be cancellable.\n *\n * @remarks\n * **IMPORTANT:** please note that if the operation has already succeeded on\n * the server, calling `cancel` will not prevent or undo the operation.The\n * `cancel` method only stops further retry attempts if a previous attempt was\n * rejected by the server.\n *\n * @param delta - The delta to increment the value by. The delta can be\n * negative. Defaults to 1.\n * @param retryOnFailure - Whether to retry the operation in case of a\n * concurrent value change on the server or not. Defaults to `true`.\n *\n * @returns An object that can be used to cancel the operation.\n */\n increment(delta: number = 1, retryOnFailure: boolean = true): OperationSubscription {\n const noopCancelSubscription = { cancel: () => {} };\n if (delta === 0) {\n return noopCancelSubscription;\n }\n if (!retryOnFailure) {\n const expected = this.value;\n this.replace(expected, expected + delta);\n return noopCancelSubscription;\n }\n return this.update((value) => value + delta);\n }\n\n /**\n * Adds the provided delta to the value. The delta can be negative to perform\n * a subtraction.\n * This operation does not retry in case failure due to concurrent value\n * changes from other clients have already applied to the shared value on the\n * server. If you want the operation to be retried until it succeeds, use the\n * overload with retry functionality.\n *\n * @param delta - The delta to add to the value. The delta can be negative to\n * perform a subtraction.\n * @see {@link NumberSignal.add|add(delta: number, retryOnFailure: boolean)}\n */\n add(delta: number): void;\n\n /**\n * Adds the provided delta to the value. The delta can be negative to perform\n * a subtraction.\n * If `true` passed to the `retryOnFailure` parameter, the operation is\n * retried in case of failures due to concurrent value changes on the server\n * until it succeeds. Note that the returned operation subscription can be\n * used to cancel the operation.\n *\n * @param delta - The delta to add to the value. The delta can be negative.\n * @param retryOnFailure - Whether to retry the operation in case of failures\n * due to concurrent value changes on the server or not.\n * @returns An operation subscription that can be canceled.\n */\n add(delta: number, retryOnFailure: boolean): OperationSubscription;\n\n add(delta: number, retryOnFailure?: boolean): OperationSubscription | void {\n if (delta !== 0) {\n if (retryOnFailure) {\n return this.increment(delta, retryOnFailure);\n }\n const expected = this.value;\n this.replace(expected, expected + delta);\n }\n // eslint-disable-next-line no-useless-return, consistent-return\n return;\n }\n}\n"],
5
- "mappings": "AAAA,SAAqC,mBAAmB;AAyBjD,MAAM,qBAAqB,YAAoB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA8BpD,UAAU,QAAgB,GAAG,iBAA0B,MAA6B;AAClF,UAAM,yBAAyB,EAAE,QAAQ,MAAM;AAAA,IAAC,EAAE;AAClD,QAAI,UAAU,GAAG;AACf,aAAO;AAAA,IACT;AACA,QAAI,CAAC,gBAAgB;AACnB,YAAM,WAAW,KAAK;AACtB,WAAK,QAAQ,UAAU,WAAW,KAAK;AACvC,aAAO;AAAA,IACT;AACA,WAAO,KAAK,OAAO,CAAC,UAAU,QAAQ,KAAK;AAAA,EAC7C;AAAA,EA+BA,IAAI,OAAe,gBAAwD;AACzE,QAAI,UAAU,GAAG;AACf,UAAI,gBAAgB;AAClB,eAAO,KAAK,UAAU,OAAO,cAAc;AAAA,MAC7C;AACA,YAAM,WAAW,KAAK;AACtB,WAAK,QAAQ,UAAU,WAAW,KAAK;AAAA,IACzC;AAEA;AAAA,EACF;AACF;",
6
- "names": []
7
- }