@tstdl/base 0.85.17 → 0.85.18

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.85.17",
3
+ "version": "0.85.18",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
package/rxjs/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export * from './performance-observer.js';
7
7
  export * from './resize-observer.js';
8
8
  export * from './retry-backoff.js';
9
9
  export * from './slow-array.js';
10
+ export * from './start-with-provider.js';
10
11
  export * from './teardown.js';
11
12
  export * from './timing.js';
12
13
  export * from './touch.js';
package/rxjs/index.js CHANGED
@@ -24,6 +24,7 @@ __reExport(rxjs_exports, require("./performance-observer.js"), module.exports);
24
24
  __reExport(rxjs_exports, require("./resize-observer.js"), module.exports);
25
25
  __reExport(rxjs_exports, require("./retry-backoff.js"), module.exports);
26
26
  __reExport(rxjs_exports, require("./slow-array.js"), module.exports);
27
+ __reExport(rxjs_exports, require("./start-with-provider.js"), module.exports);
27
28
  __reExport(rxjs_exports, require("./teardown.js"), module.exports);
28
29
  __reExport(rxjs_exports, require("./timing.js"), module.exports);
29
30
  __reExport(rxjs_exports, require("./touch.js"), module.exports);
@@ -0,0 +1,2 @@
1
+ import type { OperatorFunction } from 'rxjs';
2
+ export declare function startWithProvider<T, D>(valueProvider: () => D): OperatorFunction<T, T | D>;
@@ -0,0 +1,29 @@
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 start_with_provider_exports = {};
20
+ __export(start_with_provider_exports, {
21
+ startWithProvider: () => startWithProvider
22
+ });
23
+ module.exports = __toCommonJS(start_with_provider_exports);
24
+ var import_rxjs = require("rxjs");
25
+ function startWithProvider(valueProvider) {
26
+ return function startWithProvider2(source) {
27
+ return (0, import_rxjs.concat)((0, import_rxjs.defer)(() => (0, import_rxjs.of)(valueProvider())), source);
28
+ };
29
+ }
package/signals/api.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type * as Types from './implementation/index.js';
2
- export type { CreateComputedOptions, CreateEffectOptions, CreateSignalOptions, EffectCleanupRegisterFn, EffectRef, Signal, WritableSignal } from './implementation/index.js';
2
+ export type { CreateComputedOptions, CreateEffectOptions, CreateSignalOptions, EffectCleanupRegisterFn, EffectRef, Signal, ToSignalOptions, WritableSignal } from './implementation/index.js';
3
3
  export type SignalsConfiguration = {
4
4
  signal: typeof Types.signal;
5
5
  computed: typeof Types.computed;
package/signals/api.js CHANGED
@@ -28,13 +28,13 @@ __export(api_exports, {
28
28
  untracked: () => untracked
29
29
  });
30
30
  module.exports = __toCommonJS(api_exports);
31
- let signal;
32
- let computed;
33
- let effect;
34
- let untracked;
35
- let isSignal;
36
- let toSignal;
37
- let toObservable;
31
+ let signal = throwSignalsNotConfigured;
32
+ let computed = throwSignalsNotConfigured;
33
+ let effect = throwSignalsNotConfigured;
34
+ let untracked = throwSignalsNotConfigured;
35
+ let isSignal = throwSignalsNotConfigured;
36
+ let toSignal = throwSignalsNotConfigured;
37
+ let toObservable = throwSignalsNotConfigured;
38
38
  function configureSignals(configuration) {
39
39
  signal = configuration.signal;
40
40
  computed = configuration.computed;
@@ -44,3 +44,6 @@ function configureSignals(configuration) {
44
44
  toSignal = configuration.toSignal;
45
45
  toObservable = configuration.toObservable;
46
46
  }
47
+ function throwSignalsNotConfigured() {
48
+ throw new Error("Signals are not configured. Use configureDefaultSignalsImplementation() for default implementation or configureSignals() for custom implementation.");
49
+ }
@@ -71,7 +71,7 @@ class ReactiveNode {
71
71
  consumerPollProducersForChange() {
72
72
  for (const [producerId, edge] of this.producers) {
73
73
  const producer = edge.producerNode.deref();
74
- if (producer === void 0 || edge.atTrackingVersion !== this.trackingVersion) {
74
+ if (producer == null || edge.atTrackingVersion !== this.trackingVersion) {
75
75
  this.producers.delete(producerId);
76
76
  producer?.consumers.delete(this.id);
77
77
  continue;
@@ -91,7 +91,7 @@ class ReactiveNode {
91
91
  try {
92
92
  for (const [consumerId, edge] of this.consumers) {
93
93
  const consumer = edge.consumerNode.deref();
94
- if (consumer === void 0 || consumer.trackingVersion !== edge.atTrackingVersion) {
94
+ if (consumer == null || consumer.trackingVersion !== edge.atTrackingVersion) {
95
95
  this.consumers.delete(consumerId);
96
96
  consumer?.producers.delete(this.id);
97
97
  continue;
@@ -3,5 +3,6 @@ export * from './computed-with-dependencies.js';
3
3
  export * from './effect-with-dependencies.js';
4
4
  export * from './pipe.js';
5
5
  export * from './switch-map.js';
6
+ export * from './to-signal-2.js';
6
7
  export * from './types.js';
7
8
  export * from './untracked-operator.js';
package/signals/index.js CHANGED
@@ -20,5 +20,6 @@ __reExport(signals_exports, require("./computed-with-dependencies.js"), module.e
20
20
  __reExport(signals_exports, require("./effect-with-dependencies.js"), module.exports);
21
21
  __reExport(signals_exports, require("./pipe.js"), module.exports);
22
22
  __reExport(signals_exports, require("./switch-map.js"), module.exports);
23
+ __reExport(signals_exports, require("./to-signal-2.js"), module.exports);
23
24
  __reExport(signals_exports, require("./types.js"), module.exports);
24
25
  __reExport(signals_exports, require("./untracked-operator.js"), module.exports);
package/signals/pipe.d.ts CHANGED
@@ -16,7 +16,7 @@ export declare function pipe<T, A, B, C, D, E, F, G, H>(source: Signal<T>, op1:
16
16
  export declare function pipe<T, A, B, C, D, E, F, G, H, I>(source: Signal<T>, op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>, op6: OperatorFunction<E, F>, op7: OperatorFunction<F, G>, op8: OperatorFunction<G, H>, op9: OperatorFunction<H, I>): Signal<I>;
17
17
  export declare function pipe(source: Signal<unknown>, ...operators: OperatorFunction<unknown, unknown>[]): Signal<unknown>;
18
18
  /**
19
- * As we need an synchronous value for the resulting signal and effect scheduling is async, you have to provide an immediate value on subscription, for example via the {@link startWith} operator, otherwise an error is thrown.
19
+ * As we need an synchronous value for the resulting signal and effect scheduling is async, you have to provide an immediate value on subscription, for example via the `startWith` operator, otherwise an error is thrown.
20
20
  */
21
21
  export declare function rawPipe<T, A>(source: Signal<T>, op1: OperatorFunction<T, A>): Signal<A>;
22
22
  export declare function rawPipe<T, A, B>(source: Signal<T>, op1: OperatorFunction<T, A>, op2: OperatorFunction<A, B>): Signal<B>;
package/signals/pipe.js CHANGED
@@ -23,11 +23,13 @@ __export(pipe_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(pipe_exports);
25
25
  var import_rxjs = require("rxjs");
26
+ var import_start_with_provider = require("../rxjs/start-with-provider.js");
26
27
  var import_api = require("./api.js");
28
+ var import_to_signal_2 = require("./to-signal-2.js");
27
29
  function pipe(source, ...operators) {
28
- return rawPipe(source, (0, import_rxjs.startWith)(source()), (0, import_rxjs.distinctUntilChanged)(), ...operators);
30
+ return rawPipe(source, (0, import_start_with_provider.startWithProvider)(source), (0, import_rxjs.distinctUntilChanged)(), ...operators);
29
31
  }
30
32
  function rawPipe(source, ...operators) {
31
33
  const piped = (0, import_api.toObservable)(source).pipe(...operators);
32
- return (0, import_api.toSignal)(piped, { requireSync: true });
34
+ return (0, import_to_signal_2.toSignal2)(piped, { requireSync: true });
33
35
  }
@@ -0,0 +1,14 @@
1
+ import type { Subscribable } from 'rxjs';
2
+ import type { Signal, ToSignalOptions } from './api.js';
3
+ export type ToSignal2Options<T> = ToSignalOptions<T> & {
4
+ /** defer subscription until signal is used */
5
+ lazy?: boolean;
6
+ };
7
+ /** like `toSignal`, except that it uses untracked internal operations (required for some scenarios, but might be less safe in terms of bugs catching) and has the ability to subscribe lazily */
8
+ export declare function toSignal2<T>(source: Subscribable<T>): Signal<T | undefined>;
9
+ export declare function toSignal2<T>(source: Subscribable<T>, options: ToSignal2Options<undefined> & {
10
+ requireSync: true;
11
+ }): Signal<T>;
12
+ export declare function toSignal2<T, const I = undefined>(source: Subscribable<T>, options: ToSignal2Options<I> & {
13
+ requireSync?: false;
14
+ }): Signal<T | I>;
@@ -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_2_exports = {};
20
+ __export(to_signal_2_exports, {
21
+ toSignal2: () => toSignal2
22
+ });
23
+ module.exports = __toCommonJS(to_signal_2_exports);
24
+ var import_core = require("../core.js");
25
+ var import_finalization = require("../memory/finalization.js");
26
+ var import_type_guards = require("../utils/type-guards.js");
27
+ var import_api = require("./api.js");
28
+ var StateKind;
29
+ (function(StateKind2) {
30
+ StateKind2[StateKind2["NoValue"] = 0] = "NoValue";
31
+ StateKind2[StateKind2["Value"] = 1] = "Value";
32
+ StateKind2[StateKind2["Error"] = 2] = "Error";
33
+ })(StateKind || (StateKind = {}));
34
+ function toSignal2(source, options) {
35
+ const initialState = options?.requireSync == true ? { kind: StateKind.NoValue } : { kind: StateKind.Value, value: options?.initialValue };
36
+ const state = (0, import_api.signal)(initialState);
37
+ let subscription;
38
+ if (options?.lazy != true) {
39
+ subscription = subscribe(source, state, options);
40
+ }
41
+ const result = (0, import_api.computed)(() => {
42
+ if ((0, import_type_guards.isUndefined)(subscription)) {
43
+ subscription = subscribe(source, state, options);
44
+ }
45
+ const current = state();
46
+ switch (current.kind) {
47
+ case StateKind.Value:
48
+ return current.value;
49
+ case StateKind.Error:
50
+ throw current.error;
51
+ case StateKind.NoValue:
52
+ throw new Error("`toSignalLazy()` called with `requireSync` but `Observable` did not emit synchronously.");
53
+ }
54
+ });
55
+ (0, import_finalization.registerFinalization)(result, () => subscription?.unsubscribe());
56
+ return result;
57
+ }
58
+ function subscribe(source, state, options) {
59
+ const subscription = source.subscribe({
60
+ next: (value) => (0, import_api.untracked)(() => state.set({ kind: StateKind.Value, value })),
61
+ error: (error) => (0, import_api.untracked)(() => state.set({ kind: StateKind.Error, error }))
62
+ });
63
+ if ((0, import_core.isDevMode)() && options?.requireSync == true && (0, import_api.untracked)(state).kind == StateKind.NoValue) {
64
+ throw new Error("`toSignal()` called with `requireSync` but `Observable` did not emit synchronously.");
65
+ }
66
+ return subscription;
67
+ }