PATH:
usr
/
local
/
lib
/
node_modules
/
ghost-cli
/
node_modules
/
rxjs
/
internal
/
observable
import { Observable } from '../Observable'; import { SubscribableOrPromise } from '../types'; /** * Decides at subscription time which Observable will actually be subscribed. * * <span class="informal">`If` statement for Observables.</span> * * `iif` accepts a condition function and two Observables. When * an Observable returned by the operator is subscribed, condition function will be called. * Based on what boolean it returns at that moment, consumer will subscribe either to * the first Observable (if condition was true) or to the second (if condition was false). Condition * function may also not return anything - in that case condition will be evaluated as false and * second Observable will be subscribed. * * Note that Observables for both cases (true and false) are optional. If condition points to an Observable that * was left undefined, resulting stream will simply complete immediately. That allows you to, rather * than controlling which Observable will be subscribed, decide at runtime if consumer should have access * to given Observable or not. * * If you have more complex logic that requires decision between more than two Observables, {@link defer} * will probably be a better choice. Actually `iif` can be easily implemented with {@link defer} * and exists only for convenience and readability reasons. * * * ## Examples * ### Change at runtime which Observable will be subscribed * ```ts * import { iif, of } from 'rxjs'; * * let subscribeToFirst; * const firstOrSecond = iif( * () => subscribeToFirst, * of('first'), * of('second'), * ); * * subscribeToFirst = true; * firstOrSecond.subscribe(value => console.log(value)); * * // Logs: * // "first" * * subscribeToFirst = false; * firstOrSecond.subscribe(value => console.log(value)); * * // Logs: * // "second" * * ``` * * ### Control an access to an Observable * ```ts * let accessGranted; * const observableIfYouHaveAccess = iif( * () => accessGranted, * of('It seems you have an access...'), // Note that only one Observable is passed to the operator. * ); * * accessGranted = true; * observableIfYouHaveAccess.subscribe( * value => console.log(value), * err => {}, * () => console.log('The end'), * ); * * // Logs: * // "It seems you have an access..." * // "The end" * * accessGranted = false; * observableIfYouHaveAccess.subscribe( * value => console.log(value), * err => {}, * () => console.log('The end'), * ); * * // Logs: * // "The end" * ``` * * @see {@link defer} * * @param {function(): boolean} condition Condition which Observable should be chosen. * @param {Observable} [trueObservable] An Observable that will be subscribed if condition is true. * @param {Observable} [falseObservable] An Observable that will be subscribed if condition is false. * @return {Observable} Either first or second Observable, depending on condition. * @static true * @name iif * @owner Observable */ export declare function iif<T, F>(condition: () => boolean, trueResult?: SubscribableOrPromise<T>, falseResult?: SubscribableOrPromise<F>): Observable<T | F>;
[-] race.d.ts
[edit]
[-] using.d.ts
[edit]
[-] zip.js.map
[edit]
[-] bindNodeCallback.d.ts
[edit]
[-] concat.js
[edit]
[-] fromEventPattern.js
[edit]
[-] combineLatest.js
[edit]
[-] using.js
[edit]
[-] fromArray.js.map
[edit]
[-] merge.d.ts
[edit]
[-] timer.d.ts
[edit]
[-] generate.js
[edit]
[-] generate.js.map
[edit]
[+]
dom
[+]
..
[-] defer.js
[edit]
[-] ConnectableObservable.d.ts
[edit]
[-] ConnectableObservable.js
[edit]
[-] SubscribeOnObservable.d.ts
[edit]
[-] concat.js.map
[edit]
[-] iif.d.ts
[edit]
[-] from.js.map
[edit]
[-] fromPromise.d.ts
[edit]
[-] range.js.map
[edit]
[-] partition.d.ts
[edit]
[-] generate.d.ts
[edit]
[-] interval.d.ts
[edit]
[-] merge.js.map
[edit]
[-] bindCallback.js
[edit]
[-] forkJoin.js.map
[edit]
[-] bindNodeCallback.js.map
[edit]
[-] SubscribeOnObservable.js
[edit]
[-] bindCallback.d.ts
[edit]
[-] never.d.ts
[edit]
[-] interval.js
[edit]
[-] fromPromise.js.map
[edit]
[-] empty.d.ts
[edit]
[-] of.js
[edit]
[-] ConnectableObservable.js.map
[edit]
[-] throwError.js.map
[edit]
[-] iif.js
[edit]
[-] timer.js.map
[edit]
[-] merge.js
[edit]
[-] defer.d.ts
[edit]
[-] from.d.ts
[edit]
[-] fromEventPattern.d.ts
[edit]
[-] bindCallback.js.map
[edit]
[-] range.d.ts
[edit]
[-] onErrorResumeNext.js
[edit]
[-] of.d.ts
[edit]
[-] zip.d.ts
[edit]
[-] onErrorResumeNext.js.map
[edit]
[-] partition.js
[edit]
[-] fromIterable.d.ts
[edit]
[-] never.js.map
[edit]
[-] fromPromise.js
[edit]
[-] pairs.js
[edit]
[-] timer.js
[edit]
[-] interval.js.map
[edit]
[-] zip.js
[edit]
[-] iif.js.map
[edit]
[-] fromEvent.d.ts
[edit]
[-] fromArray.js
[edit]
[-] race.js
[edit]
[-] range.js
[edit]
[-] race.js.map
[edit]
[-] forkJoin.js
[edit]
[-] bindNodeCallback.js
[edit]
[-] concat.d.ts
[edit]
[-] combineLatest.d.ts
[edit]
[-] forkJoin.d.ts
[edit]
[-] throwError.d.ts
[edit]
[-] throwError.js
[edit]
[-] fromArray.d.ts
[edit]
[-] onErrorResumeNext.d.ts
[edit]
[-] fromEvent.js
[edit]
[-] empty.js.map
[edit]
[-] defer.js.map
[edit]
[-] SubscribeOnObservable.js.map
[edit]
[-] pairs.d.ts
[edit]
[-] empty.js
[edit]
[-] pairs.js.map
[edit]
[-] fromIterable.js.map
[edit]
[-] never.js
[edit]
[-] fromEventPattern.js.map
[edit]
[-] combineLatest.js.map
[edit]
[-] partition.js.map
[edit]
[-] using.js.map
[edit]
[-] fromEvent.js.map
[edit]
[-] of.js.map
[edit]
[-] from.js
[edit]
[-] fromIterable.js
[edit]