Skip to content

Instantly share code, notes, and snippets.

@kayhadrin
Created July 19, 2025 19:58
Show Gist options
  • Save kayhadrin/06ed1f26dd0c92fbbf1b1f7a12de4788 to your computer and use it in GitHub Desktop.
Save kayhadrin/06ed1f26dd0c92fbbf1b1f7a12de4788 to your computer and use it in GitHub Desktop.

Revisions

  1. kayhadrin created this gist Jul 19, 2025.
    24 changes: 24 additions & 0 deletions isObservable.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    /*
    See https://github.com/ReactiveX/rxjs/blob/5.0.2/src/util/subscribeToResult.ts#L70-L77
    And also:
    - https://github.com/ReactiveX/rxjs/blob/5.0.2/src/Observable.ts
    - https://github.com/ReactiveX/rxjs/blob/5.0.2/src/symbol/observable.ts
    */
    if (result instanceof Observable) {
    if (result._isScalar) {
    destination.next((<any>result).value);
    destination.complete();
    return null;
    } else {
    return result.subscribe(destination);
    }
    }
    // ...
    if (result && typeof result[$$observable] === 'function') {
    const obs = result[$$observable]();
    if (typeof obs.subscribe !== 'function') {
    destination.error(new TypeError('Provided object does not correctly implement Symbol.observable'));
    } else {
    return obs.subscribe(new InnerSubscriber(outerSubscriber, outerValue, outerIndex));
    }
    }