Skip to content

Commit

Permalink
Rename filter
Browse files Browse the repository at this point in the history
  • Loading branch information
XanderVertegaal committed May 24, 2024
1 parent 7360b27 commit 1809e8a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions frontend/src/app/aethel/aethel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
faChevronRight,
} from "@fortawesome/free-solid-svg-icons";
import { ActivatedRoute, Router } from "@angular/router";
import { filterOutNonNull } from "../shared/operators/IsNonNull";
import { isNonNull } from "../shared/operators/IsNonNull";

@Component({
selector: "pp-aethel",
Expand Down Expand Up @@ -56,7 +56,7 @@ export class AethelComponent implements OnInit {
this.route.queryParams
.pipe(
map((queryParams) => queryParams["query"]),
filterOutNonNull(),
isNonNull(),
distinctUntilChanged(),
takeUntilDestroyed(this.destroyRef),
)
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/app/sample/sample.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ActivatedRoute, Router } from "@angular/router";
import { AethelApiService } from "../shared/services/aethel-api.service";
import { map } from "rxjs";
import { LexicalPhrase } from "../shared/types";
import { filterOutNonNull } from "../shared/operators/IsNonNull";
import { isNonNull } from "../shared/operators/IsNonNull";

@Component({
selector: "pp-sample",
Expand All @@ -15,7 +15,7 @@ export class SampleComponent {
private sample$ = this.apiService.sampleResult$(this.sampleName);
public sampleResult$ = this.sample$.pipe(
map((response) => response?.result),
filterOutNonNull()
isNonNull()
);

constructor(
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/app/shared/operators/IsNonNull.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { filterOutNonNull } from "./IsNonNull";
import { isNonNull } from "./IsNonNull";
import { of } from "rxjs";

interface TestInterface {
Expand All @@ -12,7 +12,7 @@ describe('isNonNull', () => {
const source = of('hello', null, 123, undefined, true, testObject, testArray);
const expected = ['hello', 123, true, testArray, testObject];

source.pipe(filterOutNonNull()).subscribe((value) => {
source.pipe(isNonNull()).subscribe((value) => {
expect(expected.includes(value)).toBe(true);
});
});
Expand All @@ -23,7 +23,7 @@ describe('isNonNull', () => {
}
const input: TestInterface = { myTest: 'always succeeds' };
const source = of(null, input, undefined);
source.pipe(filterOutNonNull()).subscribe((value) => {
source.pipe(isNonNull()).subscribe((value) => {
// This should not compile if null/undefined are allowed to pass through.
testFunction(value);
});
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/shared/operators/IsNonNull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Observable, filter } from "rxjs";
* @returns An operator function that filters out null and undefined values.
* @template T The type of values emitted by the observable.
*/
export function filterOutNonNull<T>(): (source: Observable<T>) => Observable<NonNullable<T>> {
export function isNonNull<T>(): (source: Observable<T>) => Observable<NonNullable<T>> {
return function(source: Observable<T>): Observable<NonNullable<T>> {
return source.pipe(
filter((value: T): value is NonNullable<T> => value != null && value !== undefined)
Expand Down

0 comments on commit 1809e8a

Please sign in to comment.