Skip to content

Latest commit

 

History

History
44 lines (29 loc) · 1.18 KB

README.md

File metadata and controls

44 lines (29 loc) · 1.18 KB

Rx Xtra: Defer Of

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 LinkTreeGithubBuy me a coffee!

Usage

deferOf<T>(factory:() => T)

  • Parameters
    • factory: () => T Creates a value on subscription.
  • Returns

Examples

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