deferOf
is an RxJS creation operator that creates an observable from one value (like of
), but waits until subscription to create that value (like defer
).
rx-xtra.defer-of
is part of Rx Xtra
, a collection of RxJS utilities.
Created by Joel Shinness LinkTree • Github • Buy me a coffee!
deferOf<T>(factory:() => T)
- Parameters
factory
:() => T
Creates a value on subscription.
- Returns
let someValue = 1;
const deferredOfSomeValue = deferOf(() => someValue);
const observer:Observer<number> = {
next(val){ console.log('Next', val); },
complete(){ console.log('Complete'); },
error(err){ console.log('Error', err); }
}
deferredOfSomeValue.subscribe(observer);
// OUTPUT:
// Next 1
// Complete
someValue = 3
deferredOfSomeValue.subscribe(observer);
// OUTPUT:
// Next 3
// Complete