easy-signal 3.2.5 → 3.2.7
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/signalStore.d.ts +11 -7
- package/dist/signalStore.js +4 -8
- package/dist/signalStore.js.map +1 -1
- package/package.json +1 -1
- package/src/signalStore.ts +18 -5
- package/.vscode/settings.json +0 -18
package/dist/signalStore.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { ReactiveSignal,
|
|
1
|
+
import { ComputedSignal, ReactiveSignal, Unsubscribe } from './reactiveSignal';
|
|
2
|
+
export interface SignalReadStore<T> {
|
|
3
|
+
get(): T;
|
|
4
|
+
subscribe(sub: (value: T) => void): Unsubscribe;
|
|
5
|
+
}
|
|
6
|
+
export interface SignalWriteStore<T> extends SignalReadStore<T> {
|
|
7
|
+
set(value: T): void;
|
|
8
|
+
update(updater: (value: T) => T): void;
|
|
9
|
+
}
|
|
2
10
|
/**
|
|
3
11
|
* A store wrapper around a reactive signal. The store can be used to get, set, update, and subscribe to the signal.
|
|
4
12
|
* This is for use in Svelte 3-4.
|
|
5
13
|
*/
|
|
6
|
-
export declare function signalStore<T>(signal:
|
|
7
|
-
|
|
8
|
-
set: ReactiveSignal<T>;
|
|
9
|
-
update: ReactiveSignal<T>;
|
|
10
|
-
subscribe: (sub: ReactiveSignalSubscriber<T>) => import("./reactiveSignal").Unsubscribe;
|
|
11
|
-
};
|
|
14
|
+
export declare function signalStore<T>(signal: ComputedSignal<T>): SignalReadStore<T>;
|
|
15
|
+
export declare function signalStore<T>(signal: ReactiveSignal<T>): SignalWriteStore<T>;
|
package/dist/signalStore.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import { subscribe } from './reactiveSignal';
|
|
2
|
-
/**
|
|
3
|
-
* A store wrapper around a reactive signal. The store can be used to get, set, update, and subscribe to the signal.
|
|
4
|
-
* This is for use in Svelte 3-4.
|
|
5
|
-
*/
|
|
6
1
|
export function signalStore(signal) {
|
|
2
|
+
const isComputed = signal.length === 0;
|
|
7
3
|
return {
|
|
8
4
|
get: signal,
|
|
9
|
-
set: signal,
|
|
10
|
-
update: signal,
|
|
11
|
-
subscribe:
|
|
5
|
+
set: !isComputed && signal,
|
|
6
|
+
update: !isComputed && signal,
|
|
7
|
+
subscribe: signal.subscribe,
|
|
12
8
|
};
|
|
13
9
|
}
|
|
14
10
|
//# sourceMappingURL=signalStore.js.map
|
package/dist/signalStore.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signalStore.js","sourceRoot":"","sources":["../src/signalStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"signalStore.js","sourceRoot":"","sources":["../src/signalStore.ts"],"names":[],"mappings":"AAkBA,MAAM,UAAU,WAAW,CAAI,MAA6C;IAC1E,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC;IACvC,OAAO;QACL,GAAG,EAAE,MAAM;QACX,GAAG,EAAE,CAAC,UAAU,IAAI,MAAM;QAC1B,MAAM,EAAE,CAAC,UAAU,IAAI,MAAM;QAC7B,SAAS,EAAE,MAAM,CAAC,SAAS;KAC5B,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
package/src/signalStore.ts
CHANGED
|
@@ -1,14 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ComputedSignal, ReactiveSignal, Unsubscribe } from './reactiveSignal';
|
|
2
|
+
|
|
3
|
+
export interface SignalReadStore<T> {
|
|
4
|
+
get(): T;
|
|
5
|
+
subscribe(sub: (value: T) => void): Unsubscribe;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface SignalWriteStore<T> extends SignalReadStore<T> {
|
|
9
|
+
set(value: T): void;
|
|
10
|
+
update(updater: (value: T) => T): void;
|
|
11
|
+
}
|
|
2
12
|
|
|
3
13
|
/**
|
|
4
14
|
* A store wrapper around a reactive signal. The store can be used to get, set, update, and subscribe to the signal.
|
|
5
15
|
* This is for use in Svelte 3-4.
|
|
6
16
|
*/
|
|
7
|
-
export function signalStore<T>(signal:
|
|
17
|
+
export function signalStore<T>(signal: ComputedSignal<T>): SignalReadStore<T>;
|
|
18
|
+
export function signalStore<T>(signal: ReactiveSignal<T>): SignalWriteStore<T>;
|
|
19
|
+
export function signalStore<T>(signal: ReactiveSignal<T> | ComputedSignal<T>): SignalReadStore<T> | SignalWriteStore<T> {
|
|
20
|
+
const isComputed = signal.length === 0;
|
|
8
21
|
return {
|
|
9
22
|
get: signal,
|
|
10
|
-
set: signal,
|
|
11
|
-
update: signal,
|
|
12
|
-
subscribe:
|
|
23
|
+
set: !isComputed && signal,
|
|
24
|
+
update: !isComputed && signal,
|
|
25
|
+
subscribe: signal.subscribe,
|
|
13
26
|
};
|
|
14
27
|
}
|
package/.vscode/settings.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"[typescript]": {
|
|
3
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
4
|
-
},
|
|
5
|
-
"[json]": {
|
|
6
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
7
|
-
},
|
|
8
|
-
"eslint.format.enable": true,
|
|
9
|
-
"editor.codeActionsOnSave": {
|
|
10
|
-
"source.organizeImports": "explicit"
|
|
11
|
-
},
|
|
12
|
-
"editor.formatOnSave": true,
|
|
13
|
-
"eslint.validate": [
|
|
14
|
-
"javascript",
|
|
15
|
-
"javascriptreact",
|
|
16
|
-
"svelte"
|
|
17
|
-
]
|
|
18
|
-
}
|