Skip to content

Commit e3c78c5

Browse files
matthewpastrobot-houston
authored andcommitted
[ci] format
1 parent 5e46be5 commit e3c78c5

File tree

9 files changed

+55
-43
lines changed

9 files changed

+55
-43
lines changed

examples/framework-preact/src/components/Counter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { h, Fragment } from 'preact';
22
import './Counter.css';
33

44
export default function Counter({ children, count }) {
5-
const add = () => count.value++
5+
const add = () => count.value++;
66
const subtract = () => count.value--;
77

88
return (

packages/astro/test/preact-component.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ describe('Preact component', () => {
9393
expect(sigs1Raw).to.not.be.undefined;
9494
expect(sigs2Raw).to.not.be.undefined;
9595

96-
9796
const sigs1 = JSON.parse(sigs1Raw);
9897
const sigs2 = JSON.parse(sigs2Raw);
9998

packages/astro/test/ssr-response.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ describe('Using Astro.response in SSR', () => {
3636
const headers = response.headers;
3737
expect(headers.get('one-two')).to.equal('three');
3838
expect(headers.get('four-five')).to.equal('six');
39-
expect(headers.get('Cache-Control')).to.equal(`max-age=0, s-maxage=86400`)
39+
expect(headers.get('Cache-Control')).to.equal(`max-age=0, s-maxage=86400`);
4040
});
4141
});

packages/integrations/preact/src/client.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
import type { SignalLike } from './types';
21
import { h, render } from 'preact';
32
import StaticHtml from './static-html.js';
3+
import type { SignalLike } from './types';
44

55
const sharedSignalMap: Map<string, SignalLike> = new Map();
66

77
export default (element: HTMLElement) =>
8-
async (Component: any, props: Record<string, any>, { default: children, ...slotted }: Record<string, any>) => {
8+
async (
9+
Component: any,
10+
props: Record<string, any>,
11+
{ default: children, ...slotted }: Record<string, any>
12+
) => {
913
if (!element.hasAttribute('ssr')) return;
1014
for (const [key, value] of Object.entries(slotted)) {
1115
props[key] = h(StaticHtml, { value, name: key });
1216
}
1317
let signalsRaw = element.dataset.preactSignals;
14-
if(signalsRaw) {
18+
if (signalsRaw) {
1519
const { signal } = await import('@preact/signals');
1620
let signals: Record<string, string> = JSON.parse(element.dataset.preactSignals as string);
17-
for(const [propName, signalId] of Object.entries(signals)) {
18-
if(!sharedSignalMap.has(signalId)) {
21+
for (const [propName, signalId] of Object.entries(signals)) {
22+
if (!sharedSignalMap.has(signalId)) {
1923
const signalValue = signal(props[propName]);
2024
sharedSignalMap.set(signalId, signalValue);
2125
}

packages/integrations/preact/src/context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { RendererContext, SignalLike, PropNameToSignalMap } from './types';
1+
import type { PropNameToSignalMap, RendererContext, SignalLike } from './types';
22

33
export type Context = {
44
id: string;
@@ -19,7 +19,7 @@ export function getContext(result: RendererContext['result']): Context {
1919
return 'p' + this.c.toString();
2020
},
2121
signals: new Map(),
22-
propsToSignals: new Map()
22+
propsToSignals: new Map(),
2323
};
2424
contexts.set(result, ctx);
2525
return ctx;

packages/integrations/preact/src/server.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { AstroPreactAttrs, RendererContext } from './types';
2-
import { h, Component as BaseComponent } from 'preact';
1+
import { Component as BaseComponent, h } from 'preact';
32
import render from 'preact-render-to-string';
4-
import StaticHtml from './static-html.js';
53
import { getContext } from './context.js';
64
import { restoreSignalsOnProps, serializeSignals } from './signals.js';
5+
import StaticHtml from './static-html.js';
6+
import type { AstroPreactAttrs, RendererContext } from './types';
77

88
const slotName = (str: string) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w.toUpperCase());
99

@@ -38,7 +38,12 @@ function check(this: RendererContext, Component: any, props: Record<string, any>
3838
}
3939
}
4040

41-
function renderToStaticMarkup(this: RendererContext, Component: any, props: Record<string, any>, { default: children, ...slotted }: Record<string, any>) {
41+
function renderToStaticMarkup(
42+
this: RendererContext,
43+
Component: any,
44+
props: Record<string, any>,
45+
{ default: children, ...slotted }: Record<string, any>
46+
) {
4247
const ctx = getContext(this.result);
4348

4449
const slots: Record<string, ReturnType<typeof h>> = {};
@@ -60,11 +65,10 @@ function renderToStaticMarkup(this: RendererContext, Component: any, props: Reco
6065
);
6166
return {
6267
attrs,
63-
html
68+
html,
6469
};
6570
}
6671

67-
6872
/**
6973
* Reduces console noise by filtering known non-problematic errors.
7074
*
Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { AstroPreactAttrs, PropNameToSignalMap, SignalLike } from './types';
21
import type { Context } from './context';
32
import { incrementId } from './context.js';
3+
import type { AstroPreactAttrs, PropNameToSignalMap, SignalLike } from './types';
44

55
function isSignal(x: any): x is SignalLike {
66
return x != null && typeof x === 'object' && typeof x.peek === 'function' && 'value' in x;
@@ -9,40 +9,45 @@ function isSignal(x: any): x is SignalLike {
99
export function restoreSignalsOnProps(ctx: Context, props: Record<string, any>) {
1010
// Restore signal props that were mutated for serialization
1111
let propMap: PropNameToSignalMap;
12-
if(ctx.propsToSignals.has(props)) {
13-
propMap = ctx.propsToSignals.get(props)!
12+
if (ctx.propsToSignals.has(props)) {
13+
propMap = ctx.propsToSignals.get(props)!;
1414
} else {
1515
propMap = new Map();
1616
ctx.propsToSignals.set(props, propMap);
1717
}
18-
for(const [key, signal] of propMap) {
18+
for (const [key, signal] of propMap) {
1919
props[key] = signal;
2020
}
2121
return propMap;
2222
}
2323

24-
export function serializeSignals(ctx: Context, props: Record<string, any>, attrs: AstroPreactAttrs, map: PropNameToSignalMap){
25-
// Check for signals
26-
const signals: Record<string, string> = {};
27-
for(const [key, value] of Object.entries(props)) {
28-
if(isSignal(value)) {
29-
// Set the value to the current signal value
30-
// This mutates the props on purpose, so that it will be serialized correct.
31-
props[key] = value.peek();
32-
map.set(key, value);
33-
34-
let id: string;
35-
if(ctx.signals.has(value)) {
36-
id = ctx.signals.get(value)!;
37-
} else {
38-
id = incrementId(ctx);
39-
ctx.signals.set(value, id);
40-
}
41-
signals[key] = id;
24+
export function serializeSignals(
25+
ctx: Context,
26+
props: Record<string, any>,
27+
attrs: AstroPreactAttrs,
28+
map: PropNameToSignalMap
29+
) {
30+
// Check for signals
31+
const signals: Record<string, string> = {};
32+
for (const [key, value] of Object.entries(props)) {
33+
if (isSignal(value)) {
34+
// Set the value to the current signal value
35+
// This mutates the props on purpose, so that it will be serialized correct.
36+
props[key] = value.peek();
37+
map.set(key, value);
38+
39+
let id: string;
40+
if (ctx.signals.has(value)) {
41+
id = ctx.signals.get(value)!;
42+
} else {
43+
id = incrementId(ctx);
44+
ctx.signals.set(value, id);
4245
}
46+
signals[key] = id;
4347
}
48+
}
4449

45-
if(Object.keys(signals).length) {
46-
attrs['data-preact-signals'] = JSON.stringify(signals);
47-
}
50+
if (Object.keys(signals).length) {
51+
attrs['data-preact-signals'] = JSON.stringify(signals);
52+
}
4853
}

packages/integrations/preact/src/static-html.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { h } from 'preact';
77
* As a bonus, we can signal to Preact that this subtree is
88
* entirely static and will never change via `shouldComponentUpdate`.
99
*/
10-
const StaticHtml = ({ value, name }: { value: string; name?: string; }) => {
10+
const StaticHtml = ({ value, name }: { value: string; name?: string }) => {
1111
if (!value) return null;
1212
return h('astro-slot', { name, dangerouslySetInnerHTML: { __html: value } });
1313
};

packages/integrations/preact/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ export type SignalLike = {
1010
export type PropNameToSignalMap = Map<string, SignalLike>;
1111

1212
export type AstroPreactAttrs = {
13-
['data-preact-signals']?: string
13+
['data-preact-signals']?: string;
1414
};

0 commit comments

Comments
 (0)