@juulsgaard/signal-tools 18.0.0 → 18.0.2
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/async.mjs +96 -0
- package/dist/data-structures/signal-map.mjs +134 -0
- package/dist/data-structures/signal-queue.js +115 -0
- package/dist/data-structures/signal-queue.mjs +115 -0
- package/dist/data-structures/signal-set.mjs +143 -0
- package/dist/data-structures/signal-stack.js +90 -0
- package/dist/data-structures/signal-stack.mjs +90 -0
- package/dist/index.d.ts +564 -62
- package/dist/index.js +12 -1
- package/dist/index.mjs +16 -0
- package/dist/interop.mjs +11 -0
- package/dist/loading-signal.mjs +68 -0
- package/dist/operators.js +13 -0
- package/dist/operators.mjs +13 -0
- package/dist/request-state/async-request-state.js +48 -0
- package/dist/request-state/async-request-state.mjs +48 -0
- package/dist/request-state/constructors.js +25 -0
- package/dist/request-state/constructors.mjs +25 -0
- package/dist/request-state/empty-request-state.js +20 -0
- package/dist/request-state/empty-request-state.mjs +20 -0
- package/dist/request-state/error-request-state.js +20 -0
- package/dist/request-state/error-request-state.mjs +20 -0
- package/dist/request-state/loading-request-state.js +25 -0
- package/dist/request-state/loading-request-state.mjs +25 -0
- package/dist/request-state/request-state.js +39 -0
- package/dist/request-state/request-state.mjs +39 -0
- package/dist/request-state/request-tracker.js +64 -0
- package/dist/request-state/request-tracker.mjs +64 -0
- package/dist/request-state/static-request-state.js +32 -0
- package/dist/request-state/static-request-state.mjs +32 -0
- package/dist/request-state/writable-request-state.js +75 -0
- package/dist/request-state/writable-request-state.mjs +75 -0
- package/package.json +12 -11
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { of } from 'rxjs';
|
|
2
|
+
import { signal } from '@angular/core';
|
|
3
|
+
import { IValueRequestState } from './request-state.mjs';
|
|
4
|
+
|
|
5
|
+
class StaticRequestState extends IValueRequestState {
|
|
6
|
+
constructor(value) {
|
|
7
|
+
super();
|
|
8
|
+
this.value = value;
|
|
9
|
+
this.loading = signal(false);
|
|
10
|
+
this.error = signal(void 0);
|
|
11
|
+
this.failed = signal(false);
|
|
12
|
+
this.request$ = of(value);
|
|
13
|
+
this.result$ = this.request$;
|
|
14
|
+
this.result = signal(value);
|
|
15
|
+
}
|
|
16
|
+
cancel() {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
then(next, _error) {
|
|
20
|
+
next(this.value);
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
catch(_onError) {
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
finally(onComplete) {
|
|
27
|
+
onComplete();
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { StaticRequestState };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { ReplaySubject } from 'rxjs';
|
|
2
|
+
import { signal, computed } from '@angular/core';
|
|
3
|
+
import { parseError, isString, isFunction } from '@juulsgaard/ts-tools';
|
|
4
|
+
import { CancelledError } from '@juulsgaard/rxjs-tools';
|
|
5
|
+
import { IValueRequestState } from './request-state.js';
|
|
6
|
+
|
|
7
|
+
class WritableRequestState extends IValueRequestState {
|
|
8
|
+
constructor(onCancel) {
|
|
9
|
+
super();
|
|
10
|
+
this.onCancel = onCancel;
|
|
11
|
+
this._completed = false;
|
|
12
|
+
this._request$ = new ReplaySubject();
|
|
13
|
+
this.request$ = this._request$.asObservable();
|
|
14
|
+
this._result$ = new ReplaySubject();
|
|
15
|
+
this.result$ = this._result$.asObservable();
|
|
16
|
+
this._result = signal(void 0);
|
|
17
|
+
this.result = this._result.asReadonly();
|
|
18
|
+
this._loading = signal(true);
|
|
19
|
+
this.loading = this._loading.asReadonly();
|
|
20
|
+
this._error = signal(void 0);
|
|
21
|
+
this.error = this._error.asReadonly();
|
|
22
|
+
this.failed = computed(() => this._error() !== void 0);
|
|
23
|
+
this._cancelled = signal(false);
|
|
24
|
+
/** Emits true when the RequestState has been cancelled by a consumer, otherwise emits false */
|
|
25
|
+
this.cancelled = this._cancelled.asReadonly();
|
|
26
|
+
this._cancelled$ = new ReplaySubject();
|
|
27
|
+
/** Emits true when the RequestState has been cancelled by a consumer */
|
|
28
|
+
this.cancelled$ = this._cancelled$.asObservable();
|
|
29
|
+
}
|
|
30
|
+
get completed() {
|
|
31
|
+
return this._completed;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Create a Readonly version of the RequestState
|
|
35
|
+
*/
|
|
36
|
+
asReadonly() {
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Set the RequestState to an Error state
|
|
41
|
+
* @param error - The error for the RequestState
|
|
42
|
+
*/
|
|
43
|
+
setError(error) {
|
|
44
|
+
if (this.completed) return;
|
|
45
|
+
this._completed = true;
|
|
46
|
+
this._request$.error(error);
|
|
47
|
+
this._result$.complete();
|
|
48
|
+
this._loading.set(false);
|
|
49
|
+
this._error.set(parseError(error));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Set the RequestState to a completed state with a given value
|
|
53
|
+
* @param value - The value to emit
|
|
54
|
+
*/
|
|
55
|
+
setValue(value) {
|
|
56
|
+
if (this.completed) return;
|
|
57
|
+
this._completed = true;
|
|
58
|
+
this._request$.next(value);
|
|
59
|
+
this._request$.complete();
|
|
60
|
+
this._loading.set(false);
|
|
61
|
+
this._result.set(value);
|
|
62
|
+
}
|
|
63
|
+
cancel(error) {
|
|
64
|
+
if (this.completed) return false;
|
|
65
|
+
const fullError = isString(error) ? new CancelledError(error) : isFunction(error) ? error() : error;
|
|
66
|
+
this.setError(fullError);
|
|
67
|
+
this._cancelled.set(true);
|
|
68
|
+
this._cancelled$.next(true);
|
|
69
|
+
this._cancelled$.complete();
|
|
70
|
+
this.onCancel?.();
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { WritableRequestState };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { ReplaySubject } from 'rxjs';
|
|
2
|
+
import { signal, computed } from '@angular/core';
|
|
3
|
+
import { parseError, isString, isFunction } from '@juulsgaard/ts-tools';
|
|
4
|
+
import { CancelledError } from '@juulsgaard/rxjs-tools';
|
|
5
|
+
import { IValueRequestState } from './request-state.mjs';
|
|
6
|
+
|
|
7
|
+
class WritableRequestState extends IValueRequestState {
|
|
8
|
+
constructor(onCancel) {
|
|
9
|
+
super();
|
|
10
|
+
this.onCancel = onCancel;
|
|
11
|
+
this._completed = false;
|
|
12
|
+
this._request$ = new ReplaySubject();
|
|
13
|
+
this.request$ = this._request$.asObservable();
|
|
14
|
+
this._result$ = new ReplaySubject();
|
|
15
|
+
this.result$ = this._result$.asObservable();
|
|
16
|
+
this._result = signal(void 0);
|
|
17
|
+
this.result = this._result.asReadonly();
|
|
18
|
+
this._loading = signal(true);
|
|
19
|
+
this.loading = this._loading.asReadonly();
|
|
20
|
+
this._error = signal(void 0);
|
|
21
|
+
this.error = this._error.asReadonly();
|
|
22
|
+
this.failed = computed(() => this._error() !== void 0);
|
|
23
|
+
this._cancelled = signal(false);
|
|
24
|
+
/** Emits true when the RequestState has been cancelled by a consumer, otherwise emits false */
|
|
25
|
+
this.cancelled = this._cancelled.asReadonly();
|
|
26
|
+
this._cancelled$ = new ReplaySubject();
|
|
27
|
+
/** Emits true when the RequestState has been cancelled by a consumer */
|
|
28
|
+
this.cancelled$ = this._cancelled$.asObservable();
|
|
29
|
+
}
|
|
30
|
+
get completed() {
|
|
31
|
+
return this._completed;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Create a Readonly version of the RequestState
|
|
35
|
+
*/
|
|
36
|
+
asReadonly() {
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Set the RequestState to an Error state
|
|
41
|
+
* @param error - The error for the RequestState
|
|
42
|
+
*/
|
|
43
|
+
setError(error) {
|
|
44
|
+
if (this.completed) return;
|
|
45
|
+
this._completed = true;
|
|
46
|
+
this._request$.error(error);
|
|
47
|
+
this._result$.complete();
|
|
48
|
+
this._loading.set(false);
|
|
49
|
+
this._error.set(parseError(error));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Set the RequestState to a completed state with a given value
|
|
53
|
+
* @param value - The value to emit
|
|
54
|
+
*/
|
|
55
|
+
setValue(value) {
|
|
56
|
+
if (this.completed) return;
|
|
57
|
+
this._completed = true;
|
|
58
|
+
this._request$.next(value);
|
|
59
|
+
this._request$.complete();
|
|
60
|
+
this._loading.set(false);
|
|
61
|
+
this._result.set(value);
|
|
62
|
+
}
|
|
63
|
+
cancel(error) {
|
|
64
|
+
if (this.completed) return false;
|
|
65
|
+
const fullError = isString(error) ? new CancelledError(error) : isFunction(error) ? error() : error;
|
|
66
|
+
this.setError(fullError);
|
|
67
|
+
this._cancelled.set(true);
|
|
68
|
+
this._cancelled$.next(true);
|
|
69
|
+
this._cancelled$.complete();
|
|
70
|
+
this.onCancel?.();
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { WritableRequestState };
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juulsgaard/signal-tools",
|
|
3
|
-
"version": "18.0.
|
|
3
|
+
"version": "18.0.2",
|
|
4
4
|
"description": "Tools for working with Angular signals",
|
|
5
5
|
"repository": "git@github.com:Juulsgaard/signal-tools.git",
|
|
6
6
|
"homepage": "https://juulsgaard.github.io/signal-tools/",
|
|
7
|
-
"main": "dist/index.
|
|
7
|
+
"main": "dist/index.mjs",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"sideEffects": false,
|
|
@@ -14,24 +14,25 @@
|
|
|
14
14
|
"dist/**"
|
|
15
15
|
],
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@angular/core": "^18.2.
|
|
18
|
-
"@juulsgaard/ts-tools": "^1.6.
|
|
19
|
-
"@juulsgaard/rxjs-tools": "^1.7.
|
|
17
|
+
"@angular/core": "^18.2.8",
|
|
18
|
+
"@juulsgaard/ts-tools": "^1.6.5",
|
|
19
|
+
"@juulsgaard/rxjs-tools": "^1.7.6",
|
|
20
20
|
"rxjs": "^7.8.1",
|
|
21
21
|
"tslib": "^2.7.0",
|
|
22
22
|
"typescript": "~5.5.4"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@angular/core": "18.2.
|
|
26
|
-
"@juulsgaard/
|
|
27
|
-
"@
|
|
25
|
+
"@angular/core": "18.2.8",
|
|
26
|
+
"@juulsgaard/ts-tools": "1.6.5",
|
|
27
|
+
"@juulsgaard/rxjs-tools": "1.7.6",
|
|
28
|
+
"@types/jest": "^29.5.13",
|
|
28
29
|
"jest": "^29.7.0",
|
|
29
|
-
"rollup": "^4.
|
|
30
|
+
"rollup": "^4.24.0",
|
|
30
31
|
"rollup-plugin-dts": "^6.1.1",
|
|
31
32
|
"rollup-plugin-esbuild": "^6.1.1",
|
|
32
33
|
"rxjs": "7.8.1",
|
|
33
|
-
"ts-jest": "^29.2.
|
|
34
|
-
"typedoc": "^0.26.
|
|
34
|
+
"ts-jest": "^29.2.5",
|
|
35
|
+
"typedoc": "^0.26.8",
|
|
35
36
|
"typescript": "~5.5.4",
|
|
36
37
|
"tslib": "2.7.0"
|
|
37
38
|
},
|