observable.idl (4025B)
1 // GENERATED CONTENT - DO NOT EDIT 2 // Content was automatically extracted by Reffy into webref 3 // (https://github.com/w3c/webref) 4 // Source: Observable (https://wicg.github.io/observable/) 5 6 [Exposed=*] 7 interface Subscriber { 8 undefined next(any value); 9 undefined error(any error); 10 undefined complete(); 11 undefined addTeardown(VoidFunction teardown); 12 13 // True after the Subscriber is created, up until either 14 // complete()/error() are invoked, or the subscriber unsubscribes. Inside 15 // complete()/error(), this attribute is true. 16 readonly attribute boolean active; 17 18 readonly attribute AbortSignal signal; 19 }; 20 21 // SubscribeCallback is where the Observable "creator's" code lives. It's 22 // called when subscribe() is called, to set up a new subscription. 23 callback SubscribeCallback = undefined (Subscriber subscriber); 24 callback ObservableSubscriptionCallback = undefined (any value); 25 26 dictionary SubscriptionObserver { 27 ObservableSubscriptionCallback next; 28 ObservableSubscriptionCallback error; 29 VoidFunction complete; 30 }; 31 32 callback ObservableInspectorAbortHandler = undefined (any value); 33 34 dictionary ObservableInspector { 35 ObservableSubscriptionCallback next; 36 ObservableSubscriptionCallback error; 37 VoidFunction complete; 38 39 VoidFunction subscribe; 40 ObservableInspectorAbortHandler abort; 41 }; 42 43 typedef (ObservableSubscriptionCallback or SubscriptionObserver) ObserverUnion; 44 typedef (ObservableSubscriptionCallback or ObservableInspector) ObservableInspectorUnion; 45 46 dictionary SubscribeOptions { 47 AbortSignal signal; 48 }; 49 50 callback Predicate = boolean (any value, unsigned long long index); 51 callback Reducer = any (any accumulator, any currentValue, unsigned long long index); 52 callback Mapper = any (any value, unsigned long long index); 53 // Differs from Mapper only in return type, since this callback is exclusively 54 // used to visit each element in a sequence, not transform it. 55 callback Visitor = undefined (any value, unsigned long long index); 56 57 // This callback returns an `any` that must convert into an `Observable`, via 58 // the `Observable` conversion semantics. 59 callback CatchCallback = any (any value); 60 61 [Exposed=*] 62 interface Observable { 63 constructor(SubscribeCallback callback); 64 undefined subscribe(optional ObserverUnion observer = {}, optional SubscribeOptions options = {}); 65 66 // Constructs a native Observable from value if it's any of the following: 67 // - Observable 68 // - AsyncIterable 69 // - Iterable 70 // - Promise 71 static Observable from(any value); 72 73 // Observable-returning operators. See "Operators" section in the spec. 74 // 75 // takeUntil() can consume promises, iterables, async iterables, and other 76 // observables. 77 Observable takeUntil(any value); 78 Observable map(Mapper mapper); 79 Observable filter(Predicate predicate); 80 Observable take(unsigned long long amount); 81 Observable drop(unsigned long long amount); 82 Observable flatMap(Mapper mapper); 83 Observable switchMap(Mapper mapper); 84 Observable inspect(optional ObservableInspectorUnion inspectorUnion = {}); 85 Observable catch(CatchCallback callback); 86 Observable finally(VoidFunction callback); 87 88 // Promise-returning operators. 89 Promise<sequence<any>> toArray(optional SubscribeOptions options = {}); 90 Promise<undefined> forEach(Visitor callback, optional SubscribeOptions options = {}); 91 Promise<boolean> every(Predicate predicate, optional SubscribeOptions options = {}); 92 Promise<any> first(optional SubscribeOptions options = {}); 93 Promise<any> last(optional SubscribeOptions options = {}); 94 Promise<any> find(Predicate predicate, optional SubscribeOptions options = {}); 95 Promise<boolean> some(Predicate predicate, optional SubscribeOptions options = {}); 96 Promise<any> reduce(Reducer reducer, optional any initialValue, optional SubscribeOptions options = {}); 97 }; 98 99 dictionary ObservableEventListenerOptions { 100 boolean capture = false; 101 boolean passive; 102 }; 103 104 partial interface EventTarget { 105 Observable when(DOMString type, optional ObservableEventListenerOptions options = {}); 106 };