0.1.6 • Published 4 years ago

ngx-delay-if v0.1.6

Weekly downloads
16
License
MIT
Repository
github
Last release
4 years ago

NgxDelayIf

If you need to delay emitting values based on their content you are right here. Use this library to implement conditional delaying emitting values.

Installation

npm install ngx-delay-if
# Or if you use yarn
yarn add ngx-delay-if

Usage

import delayIf follows:

import { delayIf } from 'ngx-delay-if';

and then use it as as the samples below.

Sample 1

// Delay emitting even values for 10 seconds
obs$.pipe(delayIf(
	value => value % 2 === 0, 
	value => value * 1000)).subscribe(
	value => {
		console.log(value);
	});
Output:
1  3  5  7  9  0  2  4  6  8  10  

Sample 2

const obs$ = interval(10);

// Delay emitting odd values for (1 * value) seconds
obs$.pipe(delayIf(
	value => value % 2 === 1, 
	value => value * 1000)).subscribe(
	value => {
		console.log(value);
	});
Output:
0  2  1  4  6  3  8  10  5  7  9   

Live demo

Try it on stackblitz

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.0.1

4 years ago