Skip to content

Commit 4089c81

Browse files
committed
perf: cleanup code
1 parent 4b879e5 commit 4089c81

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

libs/ngx-breakpoint-observer/src/lib/observe-media-query.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,29 @@ import { effect, type Signal, signal, untracked } from '@angular/core';
66
* @param query
77
*/
88
export function observeMediaQuery(query: string): Signal<boolean> {
9-
const isSupported = signal(
10-
window && 'matchMedia' in window && typeof window.matchMedia === 'function'
11-
);
9+
const isSupported =
10+
window && 'matchMedia' in window && typeof window.matchMedia === 'function';
1211

1312
let mediaQuery: MediaQueryList | undefined;
1413
const matches = signal(false);
1514

1615
const cleanup = () => {
1716
if (!mediaQuery) return;
18-
1917
mediaQuery.removeEventListener('change', update);
2018
};
2119

2220
const update = () => {
23-
if (!isSupported()) return;
24-
21+
if (!isSupported) return;
2522
mediaQuery = window.matchMedia(query);
2623
untracked(() => matches.set(!!mediaQuery?.matches));
2724

2825
if (!mediaQuery) return;
29-
3026
mediaQuery.addEventListener('change', update);
3127
};
3228

3329
effect(onCleanup => {
3430
update();
35-
onCleanup(() => cleanup());
31+
onCleanup(cleanup);
3632
});
3733

3834
return matches.asReadonly();

0 commit comments

Comments
 (0)