@tstdl/base 0.84.4 → 0.84.6

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.
Files changed (37) hide show
  1. package/browser/document-controller.d.ts +1 -1
  2. package/browser/document-controller.js +1 -1
  3. package/browser/page-controller.d.ts +1 -1
  4. package/browser/page-controller.js +1 -1
  5. package/package.json +2 -1
  6. package/signals/api.d.ts +15 -0
  7. package/signals/api.js +40 -0
  8. package/signals/computed-with-dependencies.d.ts +2 -0
  9. package/signals/computed-with-dependencies.js +36 -0
  10. package/signals/implementation/api.d.ts +62 -0
  11. package/signals/implementation/api.js +43 -0
  12. package/signals/implementation/computed.d.ts +25 -0
  13. package/signals/implementation/computed.js +118 -0
  14. package/signals/implementation/configure.d.ts +1 -0
  15. package/signals/implementation/configure.js +38 -0
  16. package/signals/implementation/effect.d.ts +54 -0
  17. package/signals/implementation/effect.js +82 -0
  18. package/signals/implementation/errors.d.ts +9 -0
  19. package/signals/implementation/errors.js +41 -0
  20. package/signals/implementation/graph.d.ts +108 -0
  21. package/signals/implementation/graph.js +155 -0
  22. package/signals/implementation/index.d.ts +8 -0
  23. package/signals/implementation/index.js +25 -0
  24. package/signals/implementation/signal.d.ts +53 -0
  25. package/signals/implementation/signal.js +117 -0
  26. package/signals/implementation/untracked.d.ts +14 -0
  27. package/signals/implementation/untracked.js +39 -0
  28. package/signals/implementation/watch.d.ts +44 -0
  29. package/signals/implementation/watch.js +84 -0
  30. package/signals/index.d.ts +5 -0
  31. package/signals/index.js +22 -0
  32. package/signals/pipe.d.ts +7 -0
  33. package/signals/pipe.js +30 -0
  34. package/signals/to-observable.d.ts +16 -0
  35. package/signals/to-observable.js +38 -0
  36. package/signals/to-signal.d.ts +84 -0
  37. package/signals/to-signal.js +67 -0
@@ -0,0 +1,7 @@
1
+ import type { OperatorFunction } from 'rxjs';
2
+ import type { Signal } from './api.js';
3
+ export declare function pipe<I, A>(signal: Signal<I>, op1: OperatorFunction<I, A>): Signal<A>;
4
+ export declare function pipe<I, A, B>(signal: Signal<I>, op1: OperatorFunction<I, A>, op2: OperatorFunction<A, B>): Signal<B>;
5
+ export declare function pipe<I, A, B, C>(signal: Signal<I>, op1: OperatorFunction<I, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>): Signal<C>;
6
+ export declare function pipe<I, A, B, C, D>(signal: Signal<I>, op1: OperatorFunction<I, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>): Signal<D>;
7
+ export declare function pipe<I, A, B, C, D, E>(signal: Signal<I>, op1: OperatorFunction<I, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>): Signal<E>;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var pipe_exports = {};
20
+ __export(pipe_exports, {
21
+ pipe: () => pipe
22
+ });
23
+ module.exports = __toCommonJS(pipe_exports);
24
+ var import_to_observable = require("./to-observable.js");
25
+ var import_to_signal = require("./to-signal.js");
26
+ function pipe(signal, ...operators) {
27
+ const observable = (0, import_to_observable.toObservable)(signal, { emitImmediately: true });
28
+ const piped = observable.pipe(...operators);
29
+ return (0, import_to_signal.toSignal)(piped, { requireSync: true });
30
+ }
@@ -0,0 +1,16 @@
1
+ import { Observable } from 'rxjs';
2
+ import type { Signal } from './api.js';
3
+ export type ToObservableOptions = {
4
+ /**
5
+ * Immediately run inner effect after creation without scheduling - for advanced use cases.
6
+ */
7
+ emitImmediately: boolean;
8
+ };
9
+ /**
10
+ * Exposes the value of an Angular `Signal` as an RxJS `Observable`.
11
+ *
12
+ * The signal's value will be propagated into the `Observable`'s subscribers using an `effect`.
13
+ *
14
+ * `toObservable` must be called in an injection context.
15
+ */
16
+ export declare function toObservable<T>(source: Signal<T>, options?: ToObservableOptions): Observable<T>;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var to_observable_exports = {};
20
+ __export(to_observable_exports, {
21
+ toObservable: () => toObservable
22
+ });
23
+ module.exports = __toCommonJS(to_observable_exports);
24
+ var import_rxjs = require("rxjs");
25
+ var import_api = require("./api.js");
26
+ function toObservable(source, options) {
27
+ return new import_rxjs.Observable((subscriber) => {
28
+ const effectRef = (0, import_api.effect)(() => {
29
+ try {
30
+ const value = source();
31
+ (0, import_api.untracked)(() => subscriber.next(value));
32
+ } catch (error) {
33
+ (0, import_api.untracked)(() => subscriber.error(error));
34
+ }
35
+ }, { allowSignalWrites: true, runImmediately: options?.emitImmediately });
36
+ return () => effectRef.destroy();
37
+ });
38
+ }
@@ -0,0 +1,84 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import type { Observable } from 'rxjs';
9
+ import type { Signal } from './api.js';
10
+ export type ToSignalOptions<T> = {
11
+ /**
12
+ * Initial value for the signal produced by `toSignal`.
13
+ *
14
+ * This will be the value of the signal until the observable emits its first value.
15
+ */
16
+ initialValue?: T;
17
+ /**
18
+ * Whether to require that the observable emits synchronously when `toSignal` subscribes.
19
+ *
20
+ * If this is `true`, `toSignal` will assert that the observable produces a value immediately upon
21
+ * subscription. Setting this option removes the need to either deal with `undefined` in the
22
+ * signal type or provide an `initialValue`, at the cost of a runtime error if this requirement is
23
+ * not met.
24
+ */
25
+ requireSync?: boolean;
26
+ };
27
+ /**
28
+ * Get the current value of an `Observable` as a reactive `Signal`.
29
+ *
30
+ * `toSignal` returns a `Signal` which provides synchronous reactive access to values produced
31
+ * by the given `Observable`, by subscribing to that `Observable`. The returned `Signal` will always
32
+ * have the most recent value emitted by the subscription, and will throw an error if the
33
+ * `Observable` errors.
34
+ *
35
+ * Before the `Observable` emits its first value, the `Signal` will return `undefined`. To avoid
36
+ * this, either an `initialValue` can be passed or the `requireSync` option enabled.
37
+ */
38
+ export declare function toSignal<T>(source: Observable<T>): Signal<T | undefined>;
39
+ /**
40
+ * Get the current value of an `Observable` as a reactive `Signal`.
41
+ *
42
+ * `toSignal` returns a `Signal` which provides synchronous reactive access to values produced
43
+ * by the given `Observable`, by subscribing to that `Observable`. The returned `Signal` will always
44
+ * have the most recent value emitted by the subscription, and will throw an error if the
45
+ * `Observable` errors.
46
+ *
47
+ * Before the `Observable` emits its first value, the `Signal` will return the configured
48
+ * `initialValue`, or `undefined` if no `initialValue` is provided. If the `Observable` is
49
+ * guaranteed to emit synchronously, then the `requireSync` option can be passed instead.
50
+ */
51
+ export declare function toSignal<T>(source: Observable<T>, options?: ToSignalOptions<undefined> & {
52
+ requireSync?: false;
53
+ }): Signal<T | undefined>;
54
+ /**
55
+ * Get the current value of an `Observable` as a reactive `Signal`.
56
+ *
57
+ * `toSignal` returns a `Signal` which provides synchronous reactive access to values produced
58
+ * by the given `Observable`, by subscribing to that `Observable`. The returned `Signal` will always
59
+ * have the most recent value emitted by the subscription, and will throw an error if the
60
+ * `Observable` errors.
61
+ *
62
+ * Before the `Observable` emits its first value, the `Signal` will return the configured
63
+ * `initialValue`. If the `Observable` is guaranteed to emit synchronously, then the `requireSync`
64
+ * option can be passed instead.
65
+ */
66
+ export declare function toSignal<T, U extends T | null | undefined>(source: Observable<T>, options: ToSignalOptions<U> & {
67
+ initialValue: U;
68
+ requireSync?: false;
69
+ }): Signal<T | U>;
70
+ /**
71
+ * Get the current value of an `Observable` as a reactive `Signal`.
72
+ *
73
+ * `toSignal` returns a `Signal` which provides synchronous reactive access to values produced
74
+ * by the given `Observable`, by subscribing to that `Observable`. The returned `Signal` will always
75
+ * have the most recent value emitted by the subscription, and will throw an error if the
76
+ * `Observable` errors.
77
+ *
78
+ * With `requireSync` set to `true`, `toSignal` will assert that the `Observable` produces a value
79
+ * immediately upon subscription. No `initialValue` is needed in this case, and the returned signal
80
+ * does not include an `undefined` type.
81
+ */
82
+ export declare function toSignal<T>(source: Observable<T>, options: ToSignalOptions<undefined> & {
83
+ requireSync: true;
84
+ }): Signal<T>;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var to_signal_exports = {};
20
+ __export(to_signal_exports, {
21
+ toSignal: () => toSignal
22
+ });
23
+ module.exports = __toCommonJS(to_signal_exports);
24
+ var import_core = require("../core.js");
25
+ var import_not_supported_error = require("../error/not-supported.error.js");
26
+ var import_finalization = require("../memory/finalization.js");
27
+ var import_api = require("./api.js");
28
+ /**
29
+ * @license
30
+ * Copyright Google LLC All Rights Reserved.
31
+ *
32
+ * Use of this source code is governed by an MIT-style license that can be
33
+ * found in the LICENSE file at https://angular.io/license
34
+ */
35
+ var StateKind;
36
+ (function(StateKind2) {
37
+ StateKind2[StateKind2["NoValue"] = 0] = "NoValue";
38
+ StateKind2[StateKind2["Value"] = 1] = "Value";
39
+ StateKind2[StateKind2["Error"] = 2] = "Error";
40
+ })(StateKind || (StateKind = {}));
41
+ function toSignal(source, options = {}) {
42
+ const { initialValue, requireSync = false } = options;
43
+ const initialState = requireSync ? { kind: StateKind.NoValue } : { kind: StateKind.Value, value: initialValue };
44
+ const state = (0, import_api.signal)(initialState);
45
+ const subscription = source.subscribe({
46
+ next: (value) => state.set({ kind: StateKind.Value, value }),
47
+ error: (error) => state.set({ kind: StateKind.Error, error })
48
+ });
49
+ if ((0, import_core.isDevMode)() && requireSync && (0, import_api.untracked)(state).kind === StateKind.NoValue) {
50
+ throw new Error("`toSignal()` called with `requireSync` but `Observable` did not emit synchronously.");
51
+ }
52
+ const result = (0, import_api.computed)(() => {
53
+ const current = state();
54
+ switch (current.kind) {
55
+ case StateKind.Value:
56
+ return current.value;
57
+ case StateKind.Error:
58
+ throw current.error;
59
+ case StateKind.NoValue:
60
+ throw new Error("`toSignal()` called with `requireSync` but `Observable` did not emit synchronously.");
61
+ default:
62
+ throw new import_not_supported_error.NotSupportedError(`StateKind ${current.kind} not supported.`);
63
+ }
64
+ });
65
+ (0, import_finalization.registerFinalization)(result, () => subscription.unsubscribe());
66
+ return result;
67
+ }