observeMediaQuery
projects/core/utils/media-query-signal.ts
Description#
Subscribes apply to a media query's match state on host.
Seeds synchronously from MediaQueryList.matches, re-applies on every
change event, and returns the teardown that removes the listener. On a
host without matchMedia (SSR, jsdom) nothing is wired, apply never
fires, and the returned teardown is a no-op.
Reach for this low-level form when the query itself is reactive and the
subscription must follow it (re-wire per effect run via onCleanup);
for a static query, createMediaQuerySignal owns the teardown via
DestroyRef.
Signature#
observeMediaQuery(host, query: string, apply)Parameters#
The window-like object to read matchMedia from.
A CSS media query string, e.g. (max-width: 640px).
Receives the current match state, synchronously on subscribe and on every change.
Returns#
void Teardown that removes the change listener.