createRepeat
Import
Section titled “Import”import { createRepeat } from 'ngxtension/create-repeat';Create an RxJS repeat operator with an emit method on it, to notify when the source should be repeated.
@Component({ ..., template: ` <button (click)="repeat.emit()">Repeat</button> `})export class SomeComponent { readonly repeat = createRepeat();
// Will log 'hello' directly, then each time the 'Repeat' button gets clicked readonly #sayHello = rxEffect(of('hello').pipe(this.repeat()), console.log);}It is syntactic sugar for the following:
@Component({ ..., template: ` <button (click)="repeat$.next()">Repeat</button> `})export class SomeComponent { readonly repeat$ = new Subject<void>(); readonly #sayHello = rxEffect(of('hello').pipe(repeat({ delay: () => repeat$ }), console.log);}createRepeat overloads
Section titled “createRepeat overloads”Overload 1
Section titled “Overload 1”| arguments | type | description |
|---|---|---|
globalCount | number | Optional. Default is undefined.The number of times (applied globally) the source Observable items are repeated (a count of 0 will yield an empty Observable) |
destroyRef | DestroyRef | Optional. Default is undefined.The DestroyRef to pass when createRepeat is used outside of an injection context. |
Overload 2
Section titled “Overload 2”| arguments | type | description |
|---|---|---|
destroyRef | DestroyRef | Optional. Default is undefined.The DestroyRef to pass when createRepeat is used outside of an injection context. |
Returned repeat operator
Section titled “Returned repeat operator”| arguments | type | description |
|---|---|---|
count | number | Optional. Default is undefined.The number of times the source Observable items are repeated (a count of 0 will yield an empty Observable) |