wishthis/node_modules/rxjs/internal/operators/isEmpty.d.ts

62 lines
1.8 KiB
TypeScript
Raw Normal View History

2022-01-21 08:28:41 +00:00
import { OperatorFunction } from '../types';
/**
2022-05-29 09:24:36 +00:00
* Emits false if the input observable emits any values, or emits true if the
* input observable completes without emitting any values.
2022-01-21 08:28:41 +00:00
*
2022-05-29 09:24:36 +00:00
* <span class="informal">Tells whether any values are emitted by an observable</span>
2022-01-21 08:28:41 +00:00
*
* ![](isEmpty.png)
*
* `isEmpty` transforms an Observable that emits values into an Observable that
* emits a single boolean value representing whether or not any values were
* emitted by the source Observable. As soon as the source Observable emits a
* value, `isEmpty` will emit a `false` and complete. If the source Observable
* completes having not emitted anything, `isEmpty` will emit a `true` and
* complete.
*
* A similar effect could be achieved with {@link count}, but `isEmpty` can emit
* a `false` value sooner.
*
* ## Examples
*
* Emit `false` for a non-empty Observable
2022-05-29 09:24:36 +00:00
* ```javascript
* import { Subject } from 'rxjs';
* import { isEmpty } from 'rxjs/operators';
2022-01-21 08:28:41 +00:00
*
* const source = new Subject<string>();
* const result = source.pipe(isEmpty());
* source.subscribe(x => console.log(x));
* result.subscribe(x => console.log(x));
* source.next('a');
* source.next('b');
* source.next('c');
* source.complete();
*
2022-05-29 09:24:36 +00:00
* // Results in:
* // a
2022-01-21 08:28:41 +00:00
* // false
2022-05-29 09:24:36 +00:00
* // b
* // c
2022-01-21 08:28:41 +00:00
* ```
*
* Emit `true` for an empty Observable
2022-05-29 09:24:36 +00:00
* ```javascript
* import { EMPTY } from 'rxjs';
* import { isEmpty } from 'rxjs/operators';
2022-01-21 08:28:41 +00:00
*
* const result = EMPTY.pipe(isEmpty());
* result.subscribe(x => console.log(x));
2022-05-29 09:24:36 +00:00
* // Results in:
2022-01-21 08:28:41 +00:00
* // true
* ```
*
* @see {@link count}
* @see {@link EMPTY}
*
2022-05-29 09:24:36 +00:00
* @return {OperatorFunction<T, boolean>} An Observable of a boolean value indicating whether observable was empty or not
* @method isEmpty
* @owner Observable
2022-01-21 08:28:41 +00:00
*/
export declare function isEmpty<T>(): OperatorFunction<T, boolean>;