@vaadin/hilla-react-signals 24.5.0-alpha1 → 24.5.0-alpha10

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.
@@ -0,0 +1,97 @@
1
+ import type { ConnectClient, Subscription } from '@vaadin/hilla-frontend';
2
+ import { Signal } from './core.js';
3
+ /**
4
+ * Types of changes that can be produced or processed by a signal.
5
+ */
6
+ export declare enum StateEventType {
7
+ SET = "set",
8
+ SNAPSHOT = "snapshot"
9
+ }
10
+ /**
11
+ * An object that describes the change of the signal state.
12
+ */
13
+ export type StateEvent<T> = Readonly<{
14
+ id: string;
15
+ type: StateEventType;
16
+ value: T;
17
+ }>;
18
+ /**
19
+ * An abstraction of a signal that tracks the number of subscribers, and calls
20
+ * the provided `onSubscribe` and `onUnsubscribe` callbacks for the first
21
+ * subscription and the last unsubscription, respectively.
22
+ * @internal
23
+ */
24
+ export declare abstract class DependencyTrackingSignal<T> extends Signal<T> {
25
+ #private;
26
+ protected constructor(value: T | undefined, onFirstSubscribe: () => void, onLastUnsubscribe: () => void);
27
+ protected S(node: unknown): void;
28
+ protected U(node: unknown): void;
29
+ }
30
+ /**
31
+ * An object that describes a data object to connect to the signal provider
32
+ * service.
33
+ */
34
+ export type ServerConnectionConfig = Readonly<{
35
+ /**
36
+ * The client instance to be used for communication.
37
+ */
38
+ client: ConnectClient;
39
+ /**
40
+ * The name of the signal provider service endpoint.
41
+ */
42
+ endpoint: string;
43
+ /**
44
+ * The name of the signal provider service method.
45
+ */
46
+ method: string;
47
+ }>;
48
+ /**
49
+ * A server connection manager.
50
+ */
51
+ declare class ServerConnection<T> {
52
+ #private;
53
+ constructor(id: string, config: ServerConnectionConfig);
54
+ get subscription(): Subscription<Readonly<{
55
+ id: string;
56
+ type: StateEventType;
57
+ value: T;
58
+ }>> | undefined;
59
+ connect(): Subscription<Readonly<{
60
+ id: string;
61
+ type: StateEventType;
62
+ value: T;
63
+ }>>;
64
+ update(event: StateEvent<T>): Promise<void>;
65
+ disconnect(): void;
66
+ }
67
+ /**
68
+ * A signal that holds a shared value. Each change to the value is propagated to
69
+ * the server-side signal provider. At the same time, each change received from
70
+ * the server-side signal provider is propagated to the local signal and it's
71
+ * subscribers.
72
+ *
73
+ * @internal
74
+ */
75
+ export declare abstract class FullStackSignal<T> extends DependencyTrackingSignal<T> {
76
+ #private;
77
+ /**
78
+ * The unique identifier of the signal necessary to communicate with the
79
+ * server.
80
+ */
81
+ readonly id: string;
82
+ /**
83
+ * The server connection manager.
84
+ */
85
+ readonly server: ServerConnection<T>;
86
+ /**
87
+ * Defines whether the signal is currently awaits a server-side response.
88
+ */
89
+ readonly pending: import("@preact/signals-core").ReadonlySignal<boolean>;
90
+ /**
91
+ * Defines whether the signal has an error.
92
+ */
93
+ readonly error: import("@preact/signals-core").ReadonlySignal<Error | undefined>;
94
+ constructor(value: T | undefined, config: ServerConnectionConfig);
95
+ }
96
+ export {};
97
+ //# sourceMappingURL=FullStackSignal.d.ts.map
@@ -0,0 +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;AAIrD;;GAEG;AACH,oBAAY,cAAc;IACxB,GAAG,QAAQ;IACX,QAAQ,aAAa;CACtB;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,QAAQ,CAAC;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,CAAC,CAAC;CACV,CAAC,CAAC;AAEH;;;;;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;IAMvG,SAAS,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;IAUhC,SAAS,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;CASjC;AAED;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG,QAAQ,CAAC;IAC5C;;OAEG;IACH,MAAM,EAAE,aAAa,CAAC;IAEtB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC,CAAC;AAEH;;GAEG;AACH,cAAM,gBAAgB,CAAC,CAAC;;gBAKV,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,sBAAsB;IAKtD,IAAI,YAAY;YAhFZ,MAAM;cACJ,cAAc;;oBAiFnB;IAED,OAAO;YApFH,MAAM;cACJ,cAAc;;;IA+Fd,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjD,UAAU;CAIX;AAED;;;;;;;GAOG;AACH,8BAAsB,eAAe,CAAC,CAAC,CAAE,SAAQ,wBAAwB,CAAC,CAAC,CAAC;;IAC1E;;;OAGG;IACH,QAAQ,CAAC,EAAE,SAAY;IAEvB;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC,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;CA8CjE"}
@@ -0,0 +1,134 @@
1
+ import { nanoid } from "nanoid";
2
+ import { computed, signal, Signal } from "./core.js";
3
+ const ENDPOINT = "SignalsHandler";
4
+ var StateEventType = /* @__PURE__ */ ((StateEventType2) => {
5
+ StateEventType2["SET"] = "set";
6
+ StateEventType2["SNAPSHOT"] = "snapshot";
7
+ return StateEventType2;
8
+ })(StateEventType || {});
9
+ class DependencyTrackingSignal extends Signal {
10
+ #onFirstSubscribe;
11
+ #onLastUnsubscribe;
12
+ // -1 means to ignore the first subscription that is created internally in the
13
+ // FullStackSignal constructor.
14
+ #subscribeCount = -1;
15
+ constructor(value, onFirstSubscribe, onLastUnsubscribe) {
16
+ super(value);
17
+ this.#onFirstSubscribe = onFirstSubscribe;
18
+ this.#onLastUnsubscribe = onLastUnsubscribe;
19
+ }
20
+ S(node) {
21
+ super.S(node);
22
+ if (this.#subscribeCount === 0) {
23
+ this.#onFirstSubscribe();
24
+ }
25
+ this.#subscribeCount += 1;
26
+ }
27
+ U(node) {
28
+ super.U(node);
29
+ this.#subscribeCount -= 1;
30
+ if (this.#subscribeCount === 0) {
31
+ this.#onLastUnsubscribe();
32
+ }
33
+ }
34
+ }
35
+ class ServerConnection {
36
+ #id;
37
+ #config;
38
+ #subscription;
39
+ constructor(id, config) {
40
+ this.#config = config;
41
+ this.#id = id;
42
+ }
43
+ get subscription() {
44
+ return this.#subscription;
45
+ }
46
+ connect() {
47
+ const { client, endpoint, method } = this.#config;
48
+ this.#subscription ??= client.subscribe(ENDPOINT, "subscribe", {
49
+ providerEndpoint: endpoint,
50
+ providerMethod: method,
51
+ clientSignalId: this.#id
52
+ });
53
+ return this.#subscription;
54
+ }
55
+ async update(event) {
56
+ await this.#config.client.call(ENDPOINT, "update", {
57
+ clientSignalId: this.#id,
58
+ event
59
+ });
60
+ }
61
+ disconnect() {
62
+ this.#subscription?.cancel();
63
+ this.#subscription = void 0;
64
+ }
65
+ }
66
+ class FullStackSignal extends DependencyTrackingSignal {
67
+ /**
68
+ * The unique identifier of the signal necessary to communicate with the
69
+ * server.
70
+ */
71
+ id = nanoid();
72
+ /**
73
+ * The server connection manager.
74
+ */
75
+ server;
76
+ /**
77
+ * Defines whether the signal is currently awaits a server-side response.
78
+ */
79
+ pending = computed(() => this.#pending.value);
80
+ /**
81
+ * Defines whether the signal has an error.
82
+ */
83
+ error = computed(() => this.#error.value);
84
+ #pending = signal(false);
85
+ #error = signal(void 0);
86
+ // Paused at the very start to prevent the signal from sending the initial
87
+ // value to the server.
88
+ #paused = true;
89
+ constructor(value, config) {
90
+ super(
91
+ value,
92
+ () => this.#connect(),
93
+ () => this.#disconnect()
94
+ );
95
+ this.server = new ServerConnection(this.id, config);
96
+ this.subscribe((v) => {
97
+ if (!this.#paused) {
98
+ this.#pending.value = true;
99
+ this.#error.value = void 0;
100
+ this.server.update({
101
+ id: nanoid(),
102
+ type: "set" /* SET */,
103
+ value: v
104
+ }).catch((error) => {
105
+ this.#error.value = error instanceof Error ? error : new Error(String(error));
106
+ }).finally(() => {
107
+ this.#pending.value = false;
108
+ });
109
+ }
110
+ });
111
+ this.#paused = false;
112
+ }
113
+ #connect() {
114
+ this.server.connect().onNext((event) => {
115
+ if (event.type === "snapshot" /* SNAPSHOT */) {
116
+ this.#paused = true;
117
+ this.value = event.value;
118
+ this.#paused = false;
119
+ }
120
+ });
121
+ }
122
+ #disconnect() {
123
+ if (this.server.subscription === void 0) {
124
+ return;
125
+ }
126
+ this.server.disconnect();
127
+ }
128
+ }
129
+ export {
130
+ DependencyTrackingSignal,
131
+ FullStackSignal,
132
+ StateEventType
133
+ };
134
+ //# sourceMappingURL=FullStackSignal.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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';\n\nconst ENDPOINT = 'SignalsHandler';\n\n/**\n * Types of changes that can be produced or processed by a signal.\n */\nexport enum StateEventType {\n SET = 'set',\n SNAPSHOT = 'snapshot',\n}\n\n/**\n * An object that describes the change of the signal state.\n */\nexport type StateEvent<T> = Readonly<{\n id: string;\n type: StateEventType;\n value: T;\n}>;\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 S(node: unknown): void {\n // @ts-expect-error: We use the protected method from the base class.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n super.S(node);\n if (this.#subscribeCount === 0) {\n this.#onFirstSubscribe();\n }\n this.#subscribeCount += 1;\n }\n\n protected U(node: unknown): void {\n // @ts-expect-error: We use the protected method from the base class.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\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\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.server\n .update({\n id: nanoid(),\n type: StateEventType.SET,\n value: v,\n })\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 this.#paused = false;\n }\n\n #connect() {\n this.server.connect().onNext((event: StateEvent<T>) => {\n if (event.type === StateEventType.SNAPSHOT) {\n this.#paused = true;\n this.value = event.value;\n this.#paused = false;\n }\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;AAEzC,MAAM,WAAW;AAKV,IAAK,iBAAL,kBAAKA,oBAAL;AACL,EAAAA,gBAA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
+ "names": ["StateEventType"]
7
+ }
package/Signals.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ import { FullStackSignal } from './FullStackSignal.js';
2
+ /**
3
+ * A full-stack signal that holds an arbitrary value.
4
+ */
5
+ export declare class ValueSignal<T> extends FullStackSignal<T> {
6
+ }
7
+ /**
8
+ * A signal that holds a number value. The underlying
9
+ * value of this signal is stored and updated as a
10
+ * shared value on the server.
11
+ *
12
+ * After obtaining the NumberSignal instance from
13
+ * a server-side service that returns one, the value
14
+ * can be updated using the `value` property,
15
+ * and it can be read with or without the
16
+ * `value` property (similar to a normal signal):
17
+ *
18
+ * @example
19
+ * ```tsx
20
+ * const counter = CounterService.counter();
21
+ *
22
+ * return (
23
+ * <Button onClick={() => counter++)}>
24
+ * Click count: { counter }
25
+ * </Button>
26
+ * <Button onClick={() => counter.value = 0}>Reset</Button>
27
+ * );
28
+ * ```
29
+ */
30
+ export declare class NumberSignal extends ValueSignal<number> {
31
+ }
32
+ //# sourceMappingURL=Signals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Signals.d.ts","sourceRoot":"","sources":["src/Signals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;GAEG;AACH,qBAAa,WAAW,CAAC,CAAC,CAAE,SAAQ,eAAe,CAAC,CAAC,CAAC;CAAG;AAEzD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,YAAa,SAAQ,WAAW,CAAC,MAAM,CAAC;CAAG"}
package/Signals.js ADDED
@@ -0,0 +1,10 @@
1
+ import { FullStackSignal } from "./FullStackSignal.js";
2
+ class ValueSignal extends FullStackSignal {
3
+ }
4
+ class NumberSignal extends ValueSignal {
5
+ }
6
+ export {
7
+ NumberSignal,
8
+ ValueSignal
9
+ };
10
+ //# sourceMappingURL=Signals.js.map
package/Signals.js.map ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/Signals.ts"],
4
+ "sourcesContent": ["import { FullStackSignal } from './FullStackSignal.js';\n\n/**\n * A full-stack signal that holds an arbitrary value.\n */\nexport class ValueSignal<T> extends FullStackSignal<T> {}\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"],
5
+ "mappings": "AAAA,SAAS,uBAAuB;AAKzB,MAAM,oBAAuB,gBAAmB;AAAC;AAyBjD,MAAM,qBAAqB,YAAoB;AAAC;",
6
+ "names": []
7
+ }
package/core.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from '@preact/signals-react';
2
+ //# sourceMappingURL=core.d.ts.map
package/core.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["src/core.ts"],"names":[],"mappings":"AAKA,cAAc,uBAAuB,CAAC"}
package/core.js ADDED
@@ -0,0 +1,4 @@
1
+ import { installAutoSignalTracking } from "@preact/signals-react/runtime";
2
+ installAutoSignalTracking();
3
+ export * from "@preact/signals-react";
4
+ //# sourceMappingURL=core.js.map
package/core.js.map ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/core.ts"],
4
+ "sourcesContent": ["import { installAutoSignalTracking } from '@preact/signals-react/runtime';\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-call\ninstallAutoSignalTracking();\n\nexport * from '@preact/signals-react';\n"],
5
+ "mappings": "AAAA,SAAS,iCAAiC;AAG1C,0BAA0B;AAE1B,cAAc;",
6
+ "names": []
7
+ }
package/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
- export * from '@preact/signals-react';
1
+ export * from './core.js';
2
+ export { NumberSignal } from './Signals.js';
3
+ export { FullStackSignal } from './FullStackSignal.js';
2
4
  //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAKA,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AACA,cAAc,WAAW,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
package/index.js CHANGED
@@ -1,4 +1,8 @@
1
- import { installAutoSignalTracking } from "@preact/signals-react/runtime";
2
- installAutoSignalTracking();
3
- export * from "@preact/signals-react";
1
+ export * from "./core.js";
2
+ import { NumberSignal } from "./Signals.js";
3
+ import { FullStackSignal } from "./FullStackSignal.js";
4
+ export {
5
+ FullStackSignal,
6
+ NumberSignal
7
+ };
4
8
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["src/index.ts"],
4
- "sourcesContent": ["import { installAutoSignalTracking } from '@preact/signals-react/runtime';\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-call\ninstallAutoSignalTracking();\n\nexport * from '@preact/signals-react';\n"],
5
- "mappings": "AAAA,SAAS,iCAAiC;AAG1C,0BAA0B;AAE1B,cAAc;",
4
+ "sourcesContent": ["// eslint-disable-next-line import/export\nexport * from './core.js';\nexport { NumberSignal } from './Signals.js';\nexport { FullStackSignal } from './FullStackSignal.js';\n"],
5
+ "mappings": "AACA,cAAc;AACd,SAAS,oBAAoB;AAC7B,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-alpha1",
3
+ "version": "24.5.0-alpha10",
4
4
  "description": "Signals for Hilla React",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -21,8 +21,11 @@
21
21
  "build:esbuild": "tsx ../../../scripts/build.ts",
22
22
  "build:dts": "tsc --isolatedModules -p tsconfig.build.json",
23
23
  "build:copy": "cd src && copyfiles **/*.d.ts ..",
24
- "lint": "eslint src",
25
- "lint:fix": "eslint src --fix",
24
+ "lint": "eslint src test",
25
+ "lint:fix": "eslint src test --fix",
26
+ "test": "karma start ../../../karma.config.cjs --port 9881",
27
+ "test:coverage": "npm run test -- --coverage",
28
+ "test:watch": "npm run test -- --watch",
26
29
  "typecheck": "tsc --noEmit"
27
30
  },
28
31
  "exports": {
@@ -43,7 +46,9 @@
43
46
  "access": "public"
44
47
  },
45
48
  "dependencies": {
46
- "@preact/signals-react": "^2.0.0"
49
+ "@preact/signals-react": "^2.0.0",
50
+ "@vaadin/hilla-frontend": "24.5.0-alpha10",
51
+ "nanoid": "^5.0.7"
47
52
  },
48
53
  "peerDependencies": {
49
54
  "react": "^18",
@@ -51,10 +56,24 @@
51
56
  },
52
57
  "devDependencies": {
53
58
  "@esm-bundle/chai": "^4.3.4-fix.0",
59
+ "@testing-library/dom": "^10.2.0",
60
+ "@testing-library/react": "^16.0.0",
61
+ "@testing-library/user-event": "^14.5.2",
62
+ "@types/chai": "^4.3.6",
63
+ "@types/chai-as-promised": "^7.1.6",
64
+ "@types/chai-dom": "^1.11.1",
65
+ "@types/mocha": "^10.0.2",
54
66
  "@types/react": "^18.2.23",
55
67
  "@types/sinon": "^10.0.17",
68
+ "@types/sinon-chai": "^3.2.10",
56
69
  "@types/validator": "^13.11.2",
57
- "react-router-dom": "^6.16.0",
58
- "typescript": "5.3.2"
70
+ "chai-as-promised": "^7.1.1",
71
+ "chai-dom": "^1.11.0",
72
+ "chai-like": "^1.1.1",
73
+ "karma": "^6.4.3",
74
+ "karma-viewport": "^1.0.9",
75
+ "sinon": "^16.0.0",
76
+ "sinon-chai": "^3.7.0",
77
+ "typescript": "5.5.2"
59
78
  }
60
79
  }