-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: BIM-43424 add docs for rxjs operators
- Loading branch information
Showing
24 changed files
with
255 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 13 additions & 4 deletions
17
packages/rxjs/src/operators/distinct-until-serialized-changed.operator.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,25 @@ | ||
import { from, Observable } from 'rxjs'; | ||
import { distinctUntilSerializedChanged } from '@bimeister/utilities.rxjs'; | ||
import { from, Observable } from 'rxjs'; | ||
|
||
interface User { | ||
id: number; | ||
name: string; | ||
} | ||
|
||
describe('buffer-from-to.operator.ts', () => { | ||
it('should leave one element', () => { | ||
const source$: Observable<number> = from([1, 1, 1]); | ||
const source$: Observable<User> = from([ | ||
{ id: 1, name: 'test' }, | ||
{ id: 1, name: 'test' }, | ||
{ id: 1, name: 'test' } | ||
]); | ||
|
||
const emits: unknown[] = []; | ||
|
||
source$.pipe(distinctUntilSerializedChanged()).subscribe((output: number) => { | ||
source$.pipe(distinctUntilSerializedChanged()).subscribe((output: User) => { | ||
emits.push(output); | ||
}); | ||
|
||
expect(emits).toEqual([1]); | ||
expect(emits).toEqual([{ id: 1, name: 'test' }]); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
packages/rxjs/src/operators/distinct-until-serialized-changed.operator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
import type { MonoTypeOperatorFunction, Observable } from 'rxjs'; | ||
import { filter } from 'rxjs/operators'; | ||
|
||
export const filterFalsy = | ||
<T>(): MonoTypeOperatorFunction<T> => | ||
/** | ||
* Filters out truthy values from the source observable. | ||
* | ||
* @template T - The type of elements emitted by the source observable. | ||
* @returns - An operator that filters out truthy values from the source observable. | ||
* @example | ||
* const input$: Observable<unknown> = from([1, 'string', false, true]); | ||
input$ | ||
.pipe(filterFalsy()) | ||
.subscribe((output: unknown) => { ... }) | ||
*/ | ||
export const filterFalsy: <T>() => MonoTypeOperatorFunction<T> = | ||
<T>() => | ||
(source: Observable<T>): Observable<T> => | ||
source.pipe(filter<T>((value: T) => !Boolean(value))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
import type { MonoTypeOperatorFunction, Observable } from 'rxjs'; | ||
import { filter } from 'rxjs/operators'; | ||
|
||
export const filterTruthy = | ||
<T>(): MonoTypeOperatorFunction<T> => | ||
/** | ||
* Filters out falsy values from the source observable. | ||
* | ||
* @template T - The type of elements emitted by the source observable. | ||
* @returns - An operator that filters out falsy values from the source observable. | ||
* @example | ||
* const input$: Observable<unknown> = from([1, 'string', false, true]); | ||
input$ | ||
.pipe(filterTruthy()) | ||
.subscribe((output: unknown) => { ... }) | ||
*/ | ||
export const filterTruthy: <T>() => MonoTypeOperatorFunction<T> = | ||
<T>() => | ||
(source: Observable<T>): Observable<T> => | ||
source.pipe(filter<T>((value: T) => Boolean(value))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
import type { Observable, OperatorFunction } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
|
||
export const invertBoolean = | ||
(): OperatorFunction<boolean, boolean> => | ||
/** | ||
* Inverts boolean values emitted by the source observable. | ||
* | ||
* @returns - An operator that inverts boolean values emitted by the source observable. | ||
* @example | ||
* const input$: Observable<boolean> = of(true, true, true); | ||
input$.pipe(invertBoolean()).subscribe((result: boolean) => { ... }) | ||
*/ | ||
export const invertBoolean: () => OperatorFunction<boolean, boolean> = | ||
() => | ||
(source$: Observable<boolean>): Observable<boolean> => | ||
source$.pipe(map((value: boolean) => !value)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
import type { Observable, OperatorFunction } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
|
||
export const mapToIsFalsy = | ||
<T>(): OperatorFunction<T, boolean> => | ||
/** | ||
* Maps values emitted by the source observable to a boolean indicating whether the value is falsy. | ||
* | ||
* @template T - The type of elements emitted by the source observable. | ||
* @returns - An operator that maps values to a boolean indicating whether they are falsy. | ||
* @example | ||
* const input$: Observable<unknown> = from([1, '', 0, 'string']); | ||
input$ | ||
.pipe(mapToIsFalsy()) | ||
.subscribe((output: unknown) => { ... }) | ||
*/ | ||
export const mapToIsFalsy: <T>() => OperatorFunction<T, boolean> = | ||
<T>() => | ||
(source: Observable<T>): Observable<boolean> => | ||
source.pipe(map<T, boolean>((value: T) => !Boolean(value))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
import type { Observable, OperatorFunction } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
|
||
export const mapToIsTruthy = | ||
<T>(): OperatorFunction<T, boolean> => | ||
/** | ||
* Maps values emitted by the source observable to a boolean indicating whether the value is truthy. | ||
* | ||
* @template T - The type of elements emitted by the source observable. | ||
* @returns - An operator that maps values to a boolean indicating whether they are truthy. | ||
* @example | ||
* const input$: Observable<unknown> = from([1, '', 0, 'string']); | ||
input$ | ||
.pipe(mapToIsTruthy()) | ||
.subscribe((output: unknown) => { ... }) | ||
*/ | ||
export const mapToIsTruthy: <T>() => OperatorFunction<T, boolean> = | ||
<T>() => | ||
(source: Observable<T>): Observable<boolean> => | ||
source.pipe(map<T, boolean>((value: T) => Boolean(value))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
packages/rxjs/src/operators/share-replay-with-ref-count.operator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.