[ci] yarn format

This commit is contained in:
matthewp 2021-07-12 20:28:13 +00:00 committed by GitHub Actions
parent 0340b0f0b1
commit ea7ef71a6e
4 changed files with 14 additions and 12 deletions

View file

@ -18,15 +18,15 @@ This allows you to define components which, for example, only run on mobile devi
Since Astro components can have expressions, you can move common media queries to a module for sharing. For example here are defining:
__media.js__
**media.js**
```js
export const MOBILE = "(max-width: 700px)";
export const MOBILE = '(max-width: 700px)';
```
And then you can reference this in your page:
__index.astro__
**index.astro**
```jsx
import Sidebar from '../components/Sidebar.jsx';
@ -34,4 +34,4 @@ import { MOBILE } from '../media.js';
---
<Sidebar client:media={MOBILE} />
```
```

View file

@ -2,4 +2,4 @@ export type GetHydrateCallback = () => Promise<(element: Element, innerHTML: str
export interface HydrateOptions {
value?: string;
}
}

View file

@ -49,7 +49,7 @@ interface CodeGenOptions {
interface HydrationAttributes {
method?: 'load' | 'idle' | 'visible' | 'media';
value?: undefined | string
value?: undefined | string;
}
/** Searches through attributes to extract hydration-rlated attributes */
@ -62,7 +62,7 @@ function findHydrationAttributes(attrs: Record<string, string>): HydrationAttrib
for (const [key, val] of Object.entries(attrs)) {
if (hydrationDirectives.has(key)) {
method = key.slice(7) as HydrationAttributes['method'];
value = val === "true" ? undefined : val;
value = val === 'true' ? undefined : val;
}
}
@ -226,12 +226,14 @@ function getComponentWrapper(_name: string, hydration: HydrationAttributes, { ur
};
let metadata: string = '';
if(method) {
if (method) {
const componentUrl = getComponentUrl(astroConfig, url, pathToFileURL(filename));
const componentExport = getComponentExport();
metadata = `{ hydrate: "${method}", displayName: "${name}", componentUrl: "${componentUrl}", componentExport: ${JSON.stringify(componentExport)}, value: ${hydration.value || 'null'} }`;
metadata = `{ hydrate: "${method}", displayName: "${name}", componentUrl: "${componentUrl}", componentExport: ${JSON.stringify(componentExport)}, value: ${
hydration.value || 'null'
} }`;
} else {
metadata = `{ hydrate: undefined, displayName: "${name}", value: ${hydration.value || 'null'} }`
metadata = `{ hydrate: undefined, displayName: "${name}", value: ${hydration.value || 'null'} }`;
}
return {

View file

@ -15,9 +15,9 @@ export default async function onMedia(astroId: string, options: HydrateOptions,
};
const mql = matchMedia(options.value!);
if(mql.matches) {
if (mql.matches) {
cb();
} else {
mql.addEventListener('change', cb, {once:true});
mql.addEventListener('change', cb, { once: true });
}
}