Created
July 19, 2025 19:58
-
-
Save kayhadrin/06ed1f26dd0c92fbbf1b1f7a12de4788 to your computer and use it in GitHub Desktop.
Tip: detecting an Observable JS object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment