Skip to content

Commit 1e7adaf

Browse files
committed
Revert "[ci] format"
This reverts commit e3c78c5.
1 parent 43a030a commit 1e7adaf

File tree

9 files changed

+43
-55
lines changed

9 files changed

+43
-55
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ describe('Preact component', () => {
9393
expect(sigs1Raw).to.not.be.undefined;
9494
expect(sigs2Raw).to.not.be.undefined;
9595

96+
9697
const sigs1 = JSON.parse(sigs1Raw);
9798
const sigs2 = JSON.parse(sigs2Raw);
9899

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: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
1+
import type { SignalLike } from './types';
12
import { h, render } from 'preact';
23
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 (
9-
Component: any,
10-
props: Record<string, any>,
11-
{ default: children, ...slotted }: Record<string, any>
12-
) => {
8+
async (Component: any, props: Record<string, any>, { default: children, ...slotted }: Record<string, any>) => {
139
if (!element.hasAttribute('ssr')) return;
1410
for (const [key, value] of Object.entries(slotted)) {
1511
props[key] = h(StaticHtml, { value, name: key });
1612
}
1713
let signalsRaw = element.dataset.preactSignals;
18-
if (signalsRaw) {
14+
if(signalsRaw) {
1915
const { signal } = await import('@preact/signals');
2016
let signals: Record<string, string> = JSON.parse(element.dataset.preactSignals as string);
21-
for (const [propName, signalId] of Object.entries(signals)) {
22-
if (!sharedSignalMap.has(signalId)) {
17+
for(const [propName, signalId] of Object.entries(signals)) {
18+
if(!sharedSignalMap.has(signalId)) {
2319
const signalValue = signal(props[propName]);
2420
sharedSignalMap.set(signalId, signalValue);
2521
}

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 { PropNameToSignalMap, RendererContext, SignalLike } from './types';
1+
import type { RendererContext, SignalLike, PropNameToSignalMap } 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: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Component as BaseComponent, h } from 'preact';
1+
import type { AstroPreactAttrs, RendererContext } from './types';
2+
import { h, Component as BaseComponent } from 'preact';
23
import render from 'preact-render-to-string';
4+
import StaticHtml from './static-html.js';
35
import { getContext } from './context.js';
46
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,12 +38,7 @@ function check(this: RendererContext, Component: any, props: Record<string, any>
3838
}
3939
}
4040

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

4944
const slots: Record<string, ReturnType<typeof h>> = {};
@@ -65,10 +60,11 @@ function renderToStaticMarkup(
6560
);
6661
return {
6762
attrs,
68-
html,
63+
html
6964
};
7065
}
7166

67+
7268
/**
7369
* Reduces console noise by filtering known non-problematic errors.
7470
*
Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import type { AstroPreactAttrs, PropNameToSignalMap, SignalLike } from './types';
12
import type { Context } from './context';
23
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,45 +9,40 @@ 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(
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);
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;
4542
}
46-
signals[key] = id;
4743
}
48-
}
4944

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

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)