IssueRaiser

Simplification of Observable API

Okay, I'm going to throw my hat back in and see if I can resurrect this a little. What I'm going to propose is slightly different than the current proposal and different than RxJS, but I strongly feel it will work. ### API ```ts interface Observable<T> { new ( initialization: ( nextHandler: (value: T) => void, errorHandler: (err: any) => void, completeHandler: () => void, signal: AbortSignal ) => void; ): Observable<T> subscribe( nextHandler?: (value: T) => void, errorHandler?: (err: any) => void, completeHandler?: () => void, signal?: AbortSignal ): void; forEach(nextHandler: (value: T) => void, signal: AbortSignal): Promise<void> first(signal: AbortSignal): Promise<T>; last(signal: AbortSignal): Promise<T>; } ``` The idea is to remove the need to define `Observer` and `Subscriber`, as in other Observable implementations, and use simple functions instead. Also using a cancellation token (ala AbortController/AbortSignal) instead of introducing a `Subscription` type. I realize that `AbortController` and `AbortSignal` are not a part of JavaScript proper. However, I strongly feel JavaScript could use a cancellation primitive, and Observable, which is also a primitive, is not as useful without it. ### Defining an observable instance Below is the simplest use case for an observable. A synchronous set of values. ```ts test("should at least work", () => { const source = new Observable((next, e

Posted by benlesh on Oct 14, 2019, 3:44 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.3,500 issues0 comments

github (SaaS)

Simplification of Observable API

benleshOct 14, 2019, 3:44 PM

Okay, I'm going to throw my hat back in and see if I can resurrect this a little. What I'm going to propose is slightly different than the current proposal and different than RxJS, but I strongly feel it will work. ### API ```ts interface Observable<T> { new ( initialization: ( nextHandler: (value: T) => void, errorHandler: (err: any) => void, completeHandler: () => void, signal: AbortSignal ) => void; ): Observable<T> subscribe( nextHandler?: (value: T) => void, errorHandler?: (err: any) => void, completeHandler?: () => void, signal?: AbortSignal ): void; forEach(nextHandler: (value: T) => void, signal: AbortSignal): Promise<void> first(signal: AbortSignal): Promise<T>; last(signal: AbortSignal): Promise<T>; } ``` The idea is to remove the need to define `Observer` and `Subscriber`, as in other Observable implementations, and use simple functions instead. Also using a cancellation token (ala AbortController/AbortSignal) instead of introducing a `Subscription` type. I realize that `AbortController` and `AbortSignal` are not a part of JavaScript proper. However, I strongly feel JavaScript could use a cancellation primitive, and Observable, which is also a primitive, is not as useful without it. ### Defining an observable instance Below is the simplest use case for an observable. A synchronous set of values. ```ts test("should at least work", () => { const source = new Observable((next, e

Comments (0)

No comments yet. Start the discussion.

Comment on this issue