-
#RxJS tip, prefer
defer(() => getPromise())
overfrom(getPromise())
. The former won't callgetPromise()
until theObservable
is subscribed to, while the latter requiresgetPromise()
to be called immediately. -
For example: If
getPromise()
calls some backend, usingfrom()
will send the HTTP request immediately, even if the resultingObservable
is never subscribed to!defer()
will wait to send the HTTP request until it's actually needed.