diff --git a/README.md b/README.md index f6d4942..0dd3ca6 100644 --- a/README.md +++ b/README.md @@ -295,92 +295,6 @@ the platform, since it's an easy drop-in wherever you're handling events today. The proposed API shape can be found in https://wicg.github.io/observable/#core-infrastructure. -```js -dictionary ObservableEventListenerOptions { - boolean capture = false; - boolean passive; -}; - -partial interface EventTarget { - Observable on(DOMString type, optional ObservableEventListenerOptions options); -}; - -// `SubscribeCallback` is where the Observable "creator's" code lives. It's -// called when `subscribe()` is called, to set up a new subscription. -callback SubscribeCallback = undefined (Subscriber subscriber); -callback ObserverCallback = undefined (any value); - -dictionary Observer { - ObserverCallback next; - VoidFunction complete; - ObserverCallback error; -}; - -dictionary SubscribeOptions { - AbortSignal signal; -}; - -dictionary PromiseOptions { - AbortSignal signal; -}; - -[Exposed=*] -interface Subscriber { - undefined next(any result); - undefined complete(); - undefined error(any error); - undefined addTeardown(VoidFunction teardown); - - // True after the Subscriber is created, up until either - // `complete()`/`error()` are invoked, or the subscriber unsubscribes. Inside - // `complete()`/`error()`, this attribute is true. - readonly attribute boolean active; - - readonly attribute AbortSignal signal; -}; - -callback Predicate = boolean (any value); -callback Reducer = any (any accumulator, any currentValue) -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) - -[Exposed=*] -interface Observable { - constructor(SubscribeCallback callback); - undefined subscribe(optional Observer observer = {}, optional SubscribeOptions = {}); - - - // Constructs a native Observable from `value` if it's any of the following: - // - Observable - // - AsyncIterable - // - Iterable - // - Promise - static Observable from(any value); - - // Observable-returning operators. See "Operators" section below. - // `takeUntil()` can consume promises, iterables, async iterables, and other - // observables. - Observable takeUntil(any notifier); - Observable map(Mapper mapper); - Observable filter(Predicate predicate); - Observable take(unsigned long long); - Observable drop(unsigned long long); - Observable flatMap(Mapper mapper); - Observable finally(VoidFunction callback); - Promise> toArray(optional PromiseOptions options); - Promise forEach(Visitor callback, optional PromiseOptions options); - - // Promise-returning. See "Concerns" section below. - Promise every(Predicate predicate, optional PromiseOptions options); - // Maybe? Promise first(optional PromiseOptions options); - Promise find(Predicate predicate, optional PromiseOptions options); - Promise some(Predicate predicate, optional PromiseOptions options); - Promise reduce(Reducer reducer, optional any initialValue, optional PromiseOptions options); -}; -``` - The creator of an Observable passes in a callback that gets invoked synchronously whenever `subscribe()` is called. The `subscribe()` method can be called _any number of times_, and the callback it invokes sets up a new diff --git a/spec.bs b/spec.bs index 0970b7a..6d123a7 100644 --- a/spec.bs +++ b/spec.bs @@ -189,8 +189,6 @@ interface Observable { constructor(SubscribeCallback callback); undefined subscribe(optional ObserverUnion observer = {}, optional SubscribeOptions options = {}); - undefined finally(VoidFunction callback); - // Constructs a native Observable from value if it's any of the following: // - Observable // - AsyncIterable @@ -208,6 +206,7 @@ interface Observable { Observable take(unsigned long long amount); Observable drop(unsigned long long amount); Observable flatMap(Mapper mapper); + Observable finally(VoidFunction callback); // Promise-returning operators. Promise> toArray(optional PromiseOptions options = {});