Closed paoloricciuti closed 3 months ago
Latest commit: b99fb948a048040cdac80d208a573bfc15e99fc5
The changes in this PR will be included in the next version bump.
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
Name | Status | Preview | Last Commit |
---|---|---|---|
runed | ✅ Ready (View Log) | Visit Preview | b99fb948a048040cdac80d208a573bfc15e99fc5 |
I say we can have a helper for creating stuff outside of component init phase.
const [media, cleanup] = root(() => new MediaQuery(...));
I say we can have a helper for creating stuff outside of component init phase.
const [media, cleanup] = root(() => new MediaQuery(...));
Not a bad idea at all!
Amazing stuff, thank you!
This adds a
MediaQuery
utility where you can pass a media query and get back true or false in case it matches (with reactivity).You need to specifically pass the media query like this "(media-query-here)" so i was wondering if a warn in case the parentheses are not there could be a good thing. Maybe even add them automatically if not presents.
WDYT?
I did not add any test because for what i was able to see JSDom doesn't have a way to check media queries. I could mock that but i don't know if that's really useful.
Also also, i just created an effect in the constructor...this means it will likely fail if the instance is created in a
.svelte.ts
file. One possible way out of this could be to try to create the effect, if it fails wrap everything in$effect.root
and expose a cleanup function that users need to call in the onDestroy by themselves...but i also think there should be a standard way for every utility.