@fluixi/reactive 1.0.0-alpha.82 → 1.0.0-alpha.84
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/README.md +4 -0
- package/dist/cdn/reactive.cjs +2673 -1
- package/dist/cdn/reactive.global.js +2 -1
- package/dist/cdn/reactive.mjs +2657 -1
- package/dist/cdn/signal.cjs +299 -1
- package/dist/cdn/signal.d.ts +1 -1
- package/dist/cdn/signal.global.js +2 -1
- package/dist/cdn/signal.js +1 -1
- package/dist/cdn/signal.mjs +276 -1
- package/dist/index.cjs +2673 -1
- package/dist/index.mjs +2657 -1
- package/dist/lib/index.cjs +2674 -1
- package/dist/lib/index.js +1 -1
- package/dist/lib/index.mjs +2659 -1
- package/dist/lib/observable/index.cjs +386 -1
- package/dist/lib/observable/index.mjs +364 -1
- package/dist/lib/observable/observable.cjs +384 -1
- package/dist/lib/observable/observable.d.ts +0 -137
- package/dist/lib/observable/observable.d.ts.map +1 -1
- package/dist/lib/observable/observable.js +0 -71
- package/dist/lib/observable/observable.mjs +361 -1
- package/dist/lib/observable/subscription.cjs +180 -1
- package/dist/lib/observable/subscription.d.ts +0 -12
- package/dist/lib/observable/subscription.d.ts.map +1 -1
- package/dist/lib/observable/subscription.js +0 -12
- package/dist/lib/observable/subscription.mjs +157 -1
- package/dist/lib/observable/types.cjs +18 -1
- package/dist/lib/observable/types.d.ts.map +1 -1
- package/dist/lib/predicates.cjs +44 -1
- package/dist/lib/predicates.d.ts +2 -2
- package/dist/lib/predicates.js +2 -2
- package/dist/lib/predicates.mjs +23 -1
- package/dist/lib/signal/api.cjs +571 -1
- package/dist/lib/signal/api.d.ts +211 -1
- package/dist/lib/signal/api.d.ts.map +1 -1
- package/dist/lib/signal/api.js +207 -12
- package/dist/lib/signal/api.mjs +548 -1
- package/dist/lib/signal/cached-resource.cjs +672 -1
- package/dist/lib/signal/cached-resource.d.ts +28 -16
- package/dist/lib/signal/cached-resource.d.ts.map +1 -1
- package/dist/lib/signal/cached-resource.js +35 -29
- package/dist/lib/signal/cached-resource.mjs +650 -1
- package/dist/lib/signal/graph/children.cjs +325 -1
- package/dist/lib/signal/graph/children.js +1 -1
- package/dist/lib/signal/graph/children.mjs +302 -1
- package/dist/lib/signal/graph/compat.cjs +578 -1
- package/dist/lib/signal/graph/compat.d.ts +13 -13
- package/dist/lib/signal/graph/compat.d.ts.map +1 -1
- package/dist/lib/signal/graph/compat.js +51 -32
- package/dist/lib/signal/graph/compat.mjs +556 -1
- package/dist/lib/signal/graph/core.cjs +295 -1
- package/dist/lib/signal/graph/core.d.ts +28 -24
- package/dist/lib/signal/graph/core.d.ts.map +1 -1
- package/dist/lib/signal/graph/core.js +45 -31
- package/dist/lib/signal/graph/core.mjs +273 -1
- package/dist/lib/signal/graph/debounced.cjs +668 -1
- package/dist/lib/signal/graph/debounced.d.ts +5 -5
- package/dist/lib/signal/graph/debounced.d.ts.map +1 -1
- package/dist/lib/signal/graph/debounced.js +5 -5
- package/dist/lib/signal/graph/debounced.mjs +645 -1
- package/dist/lib/signal/graph/derived.cjs +496 -1
- package/dist/lib/signal/graph/derived.d.ts +1 -1
- package/dist/lib/signal/graph/derived.js +1 -1
- package/dist/lib/signal/graph/derived.mjs +473 -1
- package/dist/lib/signal/graph/detect.cjs +66 -1
- package/dist/lib/signal/graph/detect.mjs +45 -1
- package/dist/lib/signal/graph/error-boundary.cjs +301 -1
- package/dist/lib/signal/graph/error-boundary.js +3 -3
- package/dist/lib/signal/graph/error-boundary.mjs +278 -1
- package/dist/lib/signal/graph/index.cjs +305 -1
- package/dist/lib/signal/graph/index.d.ts +7 -6
- package/dist/lib/signal/graph/index.d.ts.map +1 -1
- package/dist/lib/signal/graph/index.js +7 -6
- package/dist/lib/signal/graph/index.mjs +283 -1
- package/dist/lib/signal/graph/observe.cjs +163 -0
- package/dist/lib/signal/graph/observe.d.ts +141 -0
- package/dist/lib/signal/graph/observe.d.ts.map +1 -0
- package/dist/lib/signal/graph/observe.js +149 -0
- package/dist/lib/signal/graph/observe.mjs +140 -0
- package/dist/lib/signal/graph/resource.cjs +620 -1
- package/dist/lib/signal/graph/resource.d.ts +1 -1
- package/dist/lib/signal/graph/resource.js +7 -8
- package/dist/lib/signal/graph/resource.mjs +597 -1
- package/dist/lib/signal/graph/runtime.cjs +501 -1
- package/dist/lib/signal/graph/runtime.d.ts +9 -9
- package/dist/lib/signal/graph/runtime.d.ts.map +1 -1
- package/dist/lib/signal/graph/runtime.js +56 -37
- package/dist/lib/signal/graph/runtime.mjs +478 -1
- package/dist/lib/signal/graph/signal-next.cjs +1208 -1
- package/dist/lib/signal/graph/signal-next.d.ts +5 -5
- package/dist/lib/signal/graph/signal-next.d.ts.map +1 -1
- package/dist/lib/signal/graph/signal-next.js +14 -12
- package/dist/lib/signal/graph/signal-next.mjs +1186 -1
- package/dist/lib/signal/graph/ssr-hooks.cjs +60 -1
- package/dist/lib/signal/graph/ssr-hooks.d.ts +6 -7
- package/dist/lib/signal/graph/ssr-hooks.d.ts.map +1 -1
- package/dist/lib/signal/graph/ssr-hooks.js +6 -7
- package/dist/lib/signal/graph/ssr-hooks.mjs +39 -1
- package/dist/lib/signal/graph/state.cjs +72 -1
- package/dist/lib/signal/graph/state.d.ts +43 -10
- package/dist/lib/signal/graph/state.d.ts.map +1 -1
- package/dist/lib/signal/graph/state.js +83 -21
- package/dist/lib/signal/graph/state.mjs +49 -1
- package/dist/lib/signal/graph/suspense.cjs +301 -1
- package/dist/lib/signal/graph/suspense.js +4 -4
- package/dist/lib/signal/graph/suspense.mjs +278 -1
- package/dist/lib/signal/index-legacy.cjs +2540 -1
- package/dist/lib/signal/index-legacy.d.ts +1 -1
- package/dist/lib/signal/index-legacy.js +1 -1
- package/dist/lib/signal/index-legacy.mjs +2518 -1
- package/dist/lib/signal/index.cjs +1275 -1
- package/dist/lib/signal/index.d.ts +5 -2
- package/dist/lib/signal/index.d.ts.map +1 -1
- package/dist/lib/signal/index.js +8 -3
- package/dist/lib/signal/index.mjs +1253 -1
- package/dist/lib/signal/list.cjs +549 -1
- package/dist/lib/signal/list.d.ts +5 -5
- package/dist/lib/signal/list.js +10 -10
- package/dist/lib/signal/list.mjs +526 -1
- package/dist/lib/signal/resource-api.cjs +626 -1
- package/dist/lib/signal/resource-api.d.ts +5 -5
- package/dist/lib/signal/resource-api.js +5 -5
- package/dist/lib/signal/resource-api.mjs +603 -1
- package/dist/lib/signal/signal.cjs +2023 -1
- package/dist/lib/signal/signal.d.ts +4 -4
- package/dist/lib/signal/signal.d.ts.map +1 -1
- package/dist/lib/signal/signal.js +22 -23
- package/dist/lib/signal/signal.mjs +2000 -1
- package/dist/lib/signal/types.cjs +38 -1
- package/dist/lib/signal/types.d.ts.map +1 -1
- package/dist/lib/signal/types.js +2 -2
- package/dist/lib/signal/types.mjs +17 -1
- package/dist/lib/signal/utilities.cjs +1012 -1
- package/dist/lib/signal/utilities.d.ts +0 -108
- package/dist/lib/signal/utilities.d.ts.map +1 -1
- package/dist/lib/signal/utilities.js +0 -158
- package/dist/lib/signal/utilities.mjs +990 -1
- package/dist/lib/store/api.cjs +612 -1
- package/dist/lib/store/api.d.ts +33 -0
- package/dist/lib/store/api.d.ts.map +1 -1
- package/dist/lib/store/api.js +41 -8
- package/dist/lib/store/api.mjs +596 -1
- package/dist/lib/store/index.cjs +691 -1
- package/dist/lib/store/index.js +1 -1
- package/dist/lib/store/index.mjs +676 -1
- package/dist/lib/store/setter.types.cjs +18 -1
- package/dist/lib/store/setter.types.d.ts +43 -3
- package/dist/lib/store/setter.types.d.ts.map +1 -1
- package/dist/lib/store/store.cjs +658 -1
- package/dist/lib/store/store.d.ts +72 -0
- package/dist/lib/store/store.d.ts.map +1 -1
- package/dist/lib/store/store.js +294 -11
- package/dist/lib/store/store.mjs +644 -1
- package/dist/lib/store/types.cjs +18 -1
- package/dist/lib/store/types.d.ts +1 -1
- package/dist/lib/store/types.d.ts.map +1 -1
- package/dist/lib/store/utils.cjs +43 -1
- package/dist/lib/store/utils.d.ts +1 -1
- package/dist/lib/store/utils.js +1 -1
- package/dist/lib/store/utils.mjs +22 -1
- package/dist/lib/subject.cjs +450 -1
- package/dist/lib/subject.js +3 -91
- package/dist/lib/subject.mjs +427 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/version.generated.cjs +27 -1
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +2 -2
- package/dist/version.generated.mjs +7 -1
- package/package.json +5 -4
|
@@ -1 +1,364 @@
|
|
|
1
|
-
|
|
1
|
+
/*! @fluixi/reactive v1.0.0-alpha.84 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
|
+
|
|
3
|
+
// src/lib/predicates.ts
|
|
4
|
+
function isFunction(value) {
|
|
5
|
+
return typeof value === "function" && !/^class\s/.test(Function.prototype.toString.call(value));
|
|
6
|
+
}
|
|
7
|
+
function isObject(value) {
|
|
8
|
+
if (value == null) return false;
|
|
9
|
+
if (Array.isArray(value)) return false;
|
|
10
|
+
if (typeof value === "function") return false;
|
|
11
|
+
if (value instanceof Date) return false;
|
|
12
|
+
if (value instanceof RegExp) return false;
|
|
13
|
+
if (value instanceof Map) return false;
|
|
14
|
+
if (value instanceof Set) return false;
|
|
15
|
+
if (value instanceof Error) return false;
|
|
16
|
+
return typeof value === "object";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/lib/observable/subscription.ts
|
|
20
|
+
var Subscription = class _Subscription {
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new Subscription.
|
|
23
|
+
*/
|
|
24
|
+
constructor(unsubscribe) {
|
|
25
|
+
/** @private */
|
|
26
|
+
this._closed = false;
|
|
27
|
+
/** @private */
|
|
28
|
+
this._parentOrParents = null;
|
|
29
|
+
/** @private */
|
|
30
|
+
this._subscriptions = null;
|
|
31
|
+
if (unsubscribe) {
|
|
32
|
+
this._subscriptions = [unsubscribe];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Whether the subscription is closed.
|
|
37
|
+
*/
|
|
38
|
+
get closed() {
|
|
39
|
+
return this._closed;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Disposes the resources held by the subscription.
|
|
43
|
+
* May be called multiple times (idempotent).
|
|
44
|
+
*/
|
|
45
|
+
unsubscribe() {
|
|
46
|
+
if (this._closed) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
this._closed = true;
|
|
50
|
+
const { _parentOrParents, _subscriptions } = this;
|
|
51
|
+
if (_parentOrParents instanceof _Subscription) {
|
|
52
|
+
_parentOrParents.remove(this);
|
|
53
|
+
} else if (_parentOrParents !== null) {
|
|
54
|
+
for (const parent of _parentOrParents) {
|
|
55
|
+
parent.remove(this);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (_subscriptions) {
|
|
59
|
+
for (const sub of _subscriptions) {
|
|
60
|
+
if (isFunction(sub) && !(sub instanceof _Subscription)) {
|
|
61
|
+
try {
|
|
62
|
+
sub();
|
|
63
|
+
} catch (error) {
|
|
64
|
+
console.error("Error in unsubscribe function:", error);
|
|
65
|
+
}
|
|
66
|
+
} else if (isObject(sub) && typeof sub.unsubscribe === "function") {
|
|
67
|
+
try {
|
|
68
|
+
sub.unsubscribe();
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.error("Error unsubscribing child:", error);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
this._subscriptions = null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Adds a child subscription or cleanup function to this subscription.
|
|
79
|
+
* When this subscription is unsubscribed, all added subscriptions/functions will be unsubscribed/called.
|
|
80
|
+
*
|
|
81
|
+
* @throws {TypeError} If the argument is not a subscription-like object or function
|
|
82
|
+
*/
|
|
83
|
+
add(subscription) {
|
|
84
|
+
if (!subscription || subscription === this) {
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
if (subscription.closed) {
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
let { _closed, _subscriptions } = this;
|
|
91
|
+
if (_closed) {
|
|
92
|
+
if (isFunction(subscription)) {
|
|
93
|
+
try {
|
|
94
|
+
subscription();
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error("Error in unsubscribe function:", error);
|
|
97
|
+
}
|
|
98
|
+
} else if (subscription.unsubscribe) {
|
|
99
|
+
try {
|
|
100
|
+
subscription.unsubscribe();
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.error("Error unsubscribing:", error);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
if (!_subscriptions) {
|
|
108
|
+
this._subscriptions = [];
|
|
109
|
+
}
|
|
110
|
+
this._subscriptions.push(subscription);
|
|
111
|
+
if (subscription instanceof _Subscription) {
|
|
112
|
+
subscription._addParent(this);
|
|
113
|
+
}
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Removes a child subscription from this subscription.
|
|
118
|
+
*/
|
|
119
|
+
remove(subscription) {
|
|
120
|
+
const { _subscriptions } = this;
|
|
121
|
+
if (!_subscriptions) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const index = _subscriptions.indexOf(subscription);
|
|
125
|
+
if (index !== -1) {
|
|
126
|
+
_subscriptions.splice(index, 1);
|
|
127
|
+
subscription._removeParent(this);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/** @private */
|
|
131
|
+
_addParent(parent) {
|
|
132
|
+
const { _parentOrParents } = this;
|
|
133
|
+
if (!_parentOrParents) {
|
|
134
|
+
this._parentOrParents = parent;
|
|
135
|
+
} else if (Array.isArray(_parentOrParents)) {
|
|
136
|
+
_parentOrParents.push(parent);
|
|
137
|
+
} else {
|
|
138
|
+
this._parentOrParents = [_parentOrParents, parent];
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/** @private */
|
|
142
|
+
_removeParent(parent) {
|
|
143
|
+
const { _parentOrParents } = this;
|
|
144
|
+
if (_parentOrParents === parent) {
|
|
145
|
+
this._parentOrParents = null;
|
|
146
|
+
} else if (Array.isArray(_parentOrParents)) {
|
|
147
|
+
const index = _parentOrParents.indexOf(parent);
|
|
148
|
+
if (index !== -1) {
|
|
149
|
+
_parentOrParents.splice(index, 1);
|
|
150
|
+
if (_parentOrParents.length === 1) {
|
|
151
|
+
this._parentOrParents = _parentOrParents[0];
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// src/lib/observable/observable.ts
|
|
159
|
+
var Subscriber = class extends Subscription {
|
|
160
|
+
/**
|
|
161
|
+
* Creates a new Subscriber.
|
|
162
|
+
*/
|
|
163
|
+
constructor(destinationOrNext, error, complete) {
|
|
164
|
+
super();
|
|
165
|
+
/** @private */
|
|
166
|
+
this.isStopped = false;
|
|
167
|
+
let observer;
|
|
168
|
+
if (!destinationOrNext) {
|
|
169
|
+
observer = {};
|
|
170
|
+
} else if (typeof destinationOrNext === "object") {
|
|
171
|
+
observer = destinationOrNext;
|
|
172
|
+
} else {
|
|
173
|
+
observer = {
|
|
174
|
+
next: destinationOrNext,
|
|
175
|
+
error,
|
|
176
|
+
complete
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
this.destination = observer;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Sends the next value to the observer.
|
|
183
|
+
*/
|
|
184
|
+
next(value) {
|
|
185
|
+
if (!this.isStopped && this.destination.next) {
|
|
186
|
+
try {
|
|
187
|
+
this.destination.next(value);
|
|
188
|
+
} catch (error) {
|
|
189
|
+
this.error(error);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Sends an error notification to the observer.
|
|
195
|
+
*/
|
|
196
|
+
error(err) {
|
|
197
|
+
if (!this.isStopped) {
|
|
198
|
+
this.isStopped = true;
|
|
199
|
+
if (this.destination.error) {
|
|
200
|
+
try {
|
|
201
|
+
this.destination.error(err);
|
|
202
|
+
} catch (error) {
|
|
203
|
+
throw error;
|
|
204
|
+
}
|
|
205
|
+
} else {
|
|
206
|
+
throw err;
|
|
207
|
+
}
|
|
208
|
+
this.unsubscribe();
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Sends a complete notification to the observer.
|
|
213
|
+
*/
|
|
214
|
+
complete() {
|
|
215
|
+
if (!this.isStopped) {
|
|
216
|
+
this.isStopped = true;
|
|
217
|
+
if (this.destination.complete) {
|
|
218
|
+
try {
|
|
219
|
+
this.destination.complete();
|
|
220
|
+
} catch (error) {
|
|
221
|
+
this.error(error);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
this.unsubscribe();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Unsubscribes the subscriber.
|
|
230
|
+
*/
|
|
231
|
+
unsubscribe() {
|
|
232
|
+
if (this.closed) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
this.isStopped = true;
|
|
236
|
+
super.unsubscribe();
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
var SafeSubscriber = class extends Subscriber {
|
|
240
|
+
constructor(observerOrNext, error, complete, parentSubscriber) {
|
|
241
|
+
super(observerOrNext, error, complete);
|
|
242
|
+
/** @private */
|
|
243
|
+
this._isUnsubscribing = false;
|
|
244
|
+
/** @private */
|
|
245
|
+
this._parentSubscriber = null;
|
|
246
|
+
this._parentSubscriber = parentSubscriber || null;
|
|
247
|
+
}
|
|
248
|
+
next(value) {
|
|
249
|
+
if (!this.isStopped && !this._isUnsubscribing) {
|
|
250
|
+
try {
|
|
251
|
+
super.next(value);
|
|
252
|
+
} catch (error) {
|
|
253
|
+
this.error(error);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
error(err) {
|
|
258
|
+
if (!this.isStopped && !this._isUnsubscribing) {
|
|
259
|
+
this._isUnsubscribing = true;
|
|
260
|
+
try {
|
|
261
|
+
super.error(err);
|
|
262
|
+
} finally {
|
|
263
|
+
this._isUnsubscribing = false;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
complete() {
|
|
268
|
+
if (!this.isStopped && !this._isUnsubscribing) {
|
|
269
|
+
this._isUnsubscribing = true;
|
|
270
|
+
try {
|
|
271
|
+
super.complete();
|
|
272
|
+
} finally {
|
|
273
|
+
this._isUnsubscribing = false;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
unsubscribe() {
|
|
278
|
+
if (this.closed) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
this._isUnsubscribing = true;
|
|
282
|
+
super.unsubscribe();
|
|
283
|
+
this._isUnsubscribing = false;
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
function operate(destination) {
|
|
287
|
+
return new Subscriber(destination.next, destination.error, destination.complete);
|
|
288
|
+
}
|
|
289
|
+
var Observable = class extends Subscription {
|
|
290
|
+
/**
|
|
291
|
+
* Creates a new Observable.
|
|
292
|
+
*/
|
|
293
|
+
constructor(subscribe) {
|
|
294
|
+
super();
|
|
295
|
+
if (subscribe) {
|
|
296
|
+
this._subscribe = subscribe;
|
|
297
|
+
} else {
|
|
298
|
+
throw new TypeError("Observable constructor requires a subscribe function");
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
subscribe(observerOrNext, error, complete) {
|
|
302
|
+
let subscriber;
|
|
303
|
+
if (observerOrNext instanceof Subscriber) {
|
|
304
|
+
subscriber = observerOrNext;
|
|
305
|
+
} else {
|
|
306
|
+
subscriber = new SafeSubscriber(observerOrNext, error, complete);
|
|
307
|
+
}
|
|
308
|
+
const { _subscribe } = this;
|
|
309
|
+
try {
|
|
310
|
+
const result = _subscribe.call(this, subscriber);
|
|
311
|
+
if (result) {
|
|
312
|
+
if (typeof result === "function") {
|
|
313
|
+
subscriber.add(result);
|
|
314
|
+
} else if (typeof result.unsubscribe === "function") {
|
|
315
|
+
subscriber.add(result);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
} catch (err) {
|
|
319
|
+
subscriber.error(err);
|
|
320
|
+
}
|
|
321
|
+
return subscriber;
|
|
322
|
+
}
|
|
323
|
+
pipe(...operations) {
|
|
324
|
+
if (operations.length === 0) {
|
|
325
|
+
return this;
|
|
326
|
+
}
|
|
327
|
+
return operations.reduce(
|
|
328
|
+
(prev, fn) => fn(prev),
|
|
329
|
+
this
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Converts the Observable to a Promise.
|
|
334
|
+
* The Promise resolves with the last emitted value when the Observable completes,
|
|
335
|
+
* or rejects if the Observable errors.
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* // Convert Observable to Promise
|
|
339
|
+
* const value = await of(1, 2, 3).toPromise();
|
|
340
|
+
* console.log(value); // 3
|
|
341
|
+
*
|
|
342
|
+
* @example
|
|
343
|
+
* // Handle empty Observable
|
|
344
|
+
* const value = await EMPTY.toPromise();
|
|
345
|
+
* console.log(value); // undefined
|
|
346
|
+
*/
|
|
347
|
+
toPromise() {
|
|
348
|
+
return new Promise((resolve, reject) => {
|
|
349
|
+
let lastValue;
|
|
350
|
+
this.subscribe({
|
|
351
|
+
next: (value) => lastValue = value,
|
|
352
|
+
error: reject,
|
|
353
|
+
complete: () => resolve(lastValue)
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
export {
|
|
359
|
+
Observable,
|
|
360
|
+
SafeSubscriber,
|
|
361
|
+
Subscriber,
|
|
362
|
+
Subscription,
|
|
363
|
+
operate
|
|
364
|
+
};
|