File: observable.idl

package info (click to toggle)
chromium 141.0.7390.107-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,254,812 kB
  • sloc: cpp: 35,264,957; ansic: 7,169,920; javascript: 4,250,185; python: 1,460,636; asm: 950,788; xml: 751,751; pascal: 187,972; sh: 89,459; perl: 88,691; objc: 79,953; sql: 53,924; cs: 44,622; fortran: 24,137; makefile: 22,319; tcl: 15,277; php: 14,018; yacc: 8,995; ruby: 7,553; awk: 3,720; lisp: 3,096; lex: 1,330; ada: 727; jsp: 228; sed: 36
file content (83 lines) | stat: -rw-r--r-- 4,064 bytes parent folder | download | duplicates (3)
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
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// https://github.com/WICG/observable

callback SubscribeCallback = void (Subscriber subscriber);
callback ObserverCallback = void (any value);
callback ObserverCompleteCallback = void ();

callback Reducer = any (any accumulator, any currentValue, unsigned long long index);
callback Mapper = any (any element, unsigned long long index);

// Differs from Mapper only in return type, since this callback is exclusively
// used to visit each element in a sequence, not transform it.
callback Visitor = undefined (any element, unsigned long long index);
// This matches the predicate in the ECMAScript Iterator helpers proposal, i.e.,
// including the `index` parameter.
callback Predicate = boolean (any value, unsigned long long index);

// This callback returns an `any` that must convert into an `Observable`, via
// the `Observable` conversion semantics.
callback CatchCallback = any (any value);

callback ObservableInspectorAbortHandler = undefined (any value);
dictionary ObservableInspector {
  ObserverCallback next;
  ObserverCallback error;
  ObserverCompleteCallback complete;

  VoidFunction subscribe;
  ObservableInspectorAbortHandler abort;
};

dictionary Observer {
  ObserverCallback next;
  ObserverCallback error;
  ObserverCompleteCallback complete;
};

dictionary SubscribeOptions {
  AbortSignal signal;
};

typedef (ObserverCallback or Observer) ObserverUnion;
typedef (ObserverCallback or ObservableInspector) ObservableInspectorUnion;

[Exposed=(Window,Worker,ShadowRealm)] // TODO(crbug.com/40282760): This should be Exposed=*
interface Observable {
  [CallWith=ScriptState, MeasureAs=ObservableConstructor] constructor(SubscribeCallback callback);
  [CallWith=ScriptState] void subscribe(optional ObserverUnion observer = {}, optional SubscribeOptions options = {});

  [CallWith=ScriptState, RaisesException] static Observable from(any value);

  // Observable-returning operators.
  // See https://wicg.github.io/observable/#observable-returning-operators.
  //
  // TODO(crbug.com/1485981): The `Observable` argument type below should be
  // `any`, and the conversion semantics (that have not yet been implemented)
  // should convert that `any` into an `Observable`.
  [CallWith=ScriptState] Observable takeUntil(Observable notifier);
  [CallWith=ScriptState] Observable map(Mapper mapper);
  [CallWith=ScriptState] Observable filter(Predicate predicate);
  [CallWith=ScriptState] Observable take(unsigned long long number_to_take);
  [CallWith=ScriptState] Observable drop(unsigned long long number_to_drop);
  [CallWith=ScriptState, RaisesException] Observable flatMap(Mapper mapper);
  [CallWith=ScriptState, RaisesException] Observable switchMap(Mapper mapper);
  [CallWith=ScriptState] Observable inspect(optional ObservableInspectorUnion inspect_observer = {});
  [CallWith=ScriptState, RaisesException, ImplementedAs=catchImpl] Observable catch(CatchCallback callback);
  [CallWith=ScriptState] Observable finally(VoidFunction callback);

  // Promise-returning operators.
  // See https://wicg.github.io/observable/#promise-returning-operators.
  [CallWith=ScriptState] Promise<sequence<any>> toArray(optional SubscribeOptions options = {});
  [CallWith=ScriptState] Promise<undefined> forEach(Visitor callback, optional SubscribeOptions options = {});
  [CallWith=ScriptState] Promise<any> first(optional SubscribeOptions options = {});
  [CallWith=ScriptState] Promise<any> last(optional SubscribeOptions options = {});
  [CallWith=ScriptState] Promise<boolean> some(Predicate predicate, optional SubscribeOptions options = {});
  [CallWith=ScriptState] Promise<boolean> every(Predicate predicate, optional SubscribeOptions options = {});
  [CallWith=ScriptState] Promise<any> find(Predicate predicate, optional SubscribeOptions options = {});
  [CallWith=ScriptState] Promise<any> reduce(Reducer reducer, optional any initialValue, optional SubscribeOptions options = {});
};