1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
use super::*;
/// The Observable class.
/// [`Observable`](https://developer.mozilla.org/en-US/docs/Web/API/Observable)
#[derive(Clone, Debug, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct Observable {
inner: Any,
}
impl FromVal for Observable {
fn from_val(v: &Any) -> Self {
Observable {
inner: Any::from_val(v),
}
}
fn take_ownership(v: AnyHandle) -> Self {
Self::from_val(&Any::take_ownership(v))
}
fn as_handle(&self) -> AnyHandle {
self.inner.as_handle()
}
}
impl core::ops::Deref for Observable {
type Target = Any;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl core::ops::DerefMut for Observable {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
impl AsRef<Any> for Observable {
fn as_ref(&self) -> &Any {
&self.inner
}
}
impl AsMut<Any> for Observable {
fn as_mut(&mut self) -> &mut Any {
&mut self.inner
}
}
impl From<Observable> for Any {
fn from(s: Observable) -> Any {
let handle = s.inner.as_handle();
core::mem::forget(s);
Any::take_ownership(handle)
}
}
impl From<&Observable> for Any {
fn from(s: &Observable) -> Any {
s.inner.clone().into()
}
}
jsbind::utils::impl_dyn_cast!(Observable);
impl Observable {
/// The `new Observable(..)` constructor, creating a new Observable instance
pub fn new(callback: &Function) -> Observable {
Self {
inner: Any::global("Observable")
.new(&[callback.into()])
.as_::<Any>(),
}
}
}
impl Observable {
/// The subscribe method.
/// [`Observable.subscribe`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/subscribe)
pub fn subscribe(&self) -> Undefined {
self.inner.call("subscribe", &[]).as_::<Undefined>()
}
}
impl Observable {
/// The subscribe method.
/// [`Observable.subscribe`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/subscribe)
pub fn subscribe_with_observer(&self, observer: &Any) -> Undefined {
self.inner
.call("subscribe", &[observer.into()])
.as_::<Undefined>()
}
}
impl Observable {
/// The subscribe method.
/// [`Observable.subscribe`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/subscribe)
pub fn subscribe_with_observer_and_options(
&self,
observer: &Any,
options: &SubscribeOptions,
) -> Undefined {
self.inner
.call("subscribe", &[observer.into(), options.into()])
.as_::<Undefined>()
}
}
impl Observable {
/// The from method.
/// [`Observable.from`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/from)
pub fn from(value: &Any) -> Observable {
Any::global("Observable")
.call("from", &[value.into()])
.as_::<Observable>()
}
}
impl Observable {
/// The takeUntil method.
/// [`Observable.takeUntil`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/takeUntil)
pub fn take_until(&self, value: &Any) -> Observable {
self.inner
.call("takeUntil", &[value.into()])
.as_::<Observable>()
}
}
impl Observable {
/// The map method.
/// [`Observable.map`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/map)
pub fn map(&self, mapper: &Function) -> Observable {
self.inner.call("map", &[mapper.into()]).as_::<Observable>()
}
}
impl Observable {
/// The filter method.
/// [`Observable.filter`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/filter)
pub fn filter(&self, predicate: &Function) -> Observable {
self.inner
.call("filter", &[predicate.into()])
.as_::<Observable>()
}
}
impl Observable {
/// The take method.
/// [`Observable.take`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/take)
pub fn take(&self, amount: u64) -> Observable {
self.inner
.call("take", &[amount.into()])
.as_::<Observable>()
}
}
impl Observable {
/// The drop method.
/// [`Observable.drop`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/drop)
pub fn drop(&self, amount: u64) -> Observable {
self.inner
.call("drop", &[amount.into()])
.as_::<Observable>()
}
}
impl Observable {
/// The flatMap method.
/// [`Observable.flatMap`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/flatMap)
pub fn flat_map(&self, mapper: &Function) -> Observable {
self.inner
.call("flatMap", &[mapper.into()])
.as_::<Observable>()
}
}
impl Observable {
/// The switchMap method.
/// [`Observable.switchMap`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/switchMap)
pub fn switch_map(&self, mapper: &Function) -> Observable {
self.inner
.call("switchMap", &[mapper.into()])
.as_::<Observable>()
}
}
impl Observable {
/// The inspect method.
/// [`Observable.inspect`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/inspect)
pub fn inspect(&self) -> Observable {
self.inner.call("inspect", &[]).as_::<Observable>()
}
}
impl Observable {
/// The inspect method.
/// [`Observable.inspect`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/inspect)
pub fn inspect_with_inspector_union(&self, inspector_union: &Any) -> Observable {
self.inner
.call("inspect", &[inspector_union.into()])
.as_::<Observable>()
}
}
impl Observable {
/// The catch method.
/// [`Observable.catch`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/catch)
pub fn catch(&self, callback: &Function) -> Observable {
self.inner
.call("catch", &[callback.into()])
.as_::<Observable>()
}
}
impl Observable {
/// The finally method.
/// [`Observable.finally`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/finally)
pub fn finally(&self, callback: &Function) -> Observable {
self.inner
.call("finally", &[callback.into()])
.as_::<Observable>()
}
}
impl Observable {
/// The toArray method.
/// [`Observable.toArray`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/toArray)
pub fn to_array(&self) -> Promise<TypedArray<Any>> {
self.inner
.call("toArray", &[])
.as_::<Promise<TypedArray<Any>>>()
}
}
impl Observable {
/// The toArray method.
/// [`Observable.toArray`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/toArray)
pub fn to_array_with_options(&self, options: &SubscribeOptions) -> Promise<TypedArray<Any>> {
self.inner
.call("toArray", &[options.into()])
.as_::<Promise<TypedArray<Any>>>()
}
}
impl Observable {
/// The forEach method.
/// [`Observable.forEach`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/forEach)
pub fn for_each(&self, callback: &Function) -> Promise<Undefined> {
self.inner
.call("forEach", &[callback.into()])
.as_::<Promise<Undefined>>()
}
}
impl Observable {
/// The forEach method.
/// [`Observable.forEach`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/forEach)
pub fn for_each_with_options(
&self,
callback: &Function,
options: &SubscribeOptions,
) -> Promise<Undefined> {
self.inner
.call("forEach", &[callback.into(), options.into()])
.as_::<Promise<Undefined>>()
}
}
impl Observable {
/// The every method.
/// [`Observable.every`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/every)
pub fn every(&self, predicate: &Function) -> Promise<bool> {
self.inner
.call("every", &[predicate.into()])
.as_::<Promise<bool>>()
}
}
impl Observable {
/// The every method.
/// [`Observable.every`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/every)
pub fn every_with_options(
&self,
predicate: &Function,
options: &SubscribeOptions,
) -> Promise<bool> {
self.inner
.call("every", &[predicate.into(), options.into()])
.as_::<Promise<bool>>()
}
}
impl Observable {
/// The first method.
/// [`Observable.first`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/first)
pub fn first(&self) -> Promise<Any> {
self.inner.call("first", &[]).as_::<Promise<Any>>()
}
}
impl Observable {
/// The first method.
/// [`Observable.first`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/first)
pub fn first_with_options(&self, options: &SubscribeOptions) -> Promise<Any> {
self.inner
.call("first", &[options.into()])
.as_::<Promise<Any>>()
}
}
impl Observable {
/// The last method.
/// [`Observable.last`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/last)
pub fn last(&self) -> Promise<Any> {
self.inner.call("last", &[]).as_::<Promise<Any>>()
}
}
impl Observable {
/// The last method.
/// [`Observable.last`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/last)
pub fn last_with_options(&self, options: &SubscribeOptions) -> Promise<Any> {
self.inner
.call("last", &[options.into()])
.as_::<Promise<Any>>()
}
}
impl Observable {
/// The find method.
/// [`Observable.find`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/find)
pub fn find(&self, predicate: &Function) -> Promise<Any> {
self.inner
.call("find", &[predicate.into()])
.as_::<Promise<Any>>()
}
}
impl Observable {
/// The find method.
/// [`Observable.find`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/find)
pub fn find_with_options(
&self,
predicate: &Function,
options: &SubscribeOptions,
) -> Promise<Any> {
self.inner
.call("find", &[predicate.into(), options.into()])
.as_::<Promise<Any>>()
}
}
impl Observable {
/// The some method.
/// [`Observable.some`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/some)
pub fn some(&self, predicate: &Function) -> Promise<bool> {
self.inner
.call("some", &[predicate.into()])
.as_::<Promise<bool>>()
}
}
impl Observable {
/// The some method.
/// [`Observable.some`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/some)
pub fn some_with_options(
&self,
predicate: &Function,
options: &SubscribeOptions,
) -> Promise<bool> {
self.inner
.call("some", &[predicate.into(), options.into()])
.as_::<Promise<bool>>()
}
}
impl Observable {
/// The reduce method.
/// [`Observable.reduce`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/reduce)
pub fn reduce(&self, reducer: &Function) -> Promise<Any> {
self.inner
.call("reduce", &[reducer.into()])
.as_::<Promise<Any>>()
}
}
impl Observable {
/// The reduce method.
/// [`Observable.reduce`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/reduce)
pub fn reduce_with_initial_value(
&self,
reducer: &Function,
initial_value: &Any,
) -> Promise<Any> {
self.inner
.call("reduce", &[reducer.into(), initial_value.into()])
.as_::<Promise<Any>>()
}
}
impl Observable {
/// The reduce method.
/// [`Observable.reduce`](https://developer.mozilla.org/en-US/docs/Web/API/Observable/reduce)
pub fn reduce_with_initial_value_and_options(
&self,
reducer: &Function,
initial_value: &Any,
options: &SubscribeOptions,
) -> Promise<Any> {
self.inner
.call(
"reduce",
&[reducer.into(), initial_value.into(), options.into()],
)
.as_::<Promise<Any>>()
}
}