Skip to content

Commit

Permalink
Better GET signature
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansolid committed Jan 25, 2024
1 parent c4de61d commit 27d60cd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/popular-mirrors-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/start": patch
---

better GET signature
6 changes: 3 additions & 3 deletions examples/experiments/src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import { clientOnly, GET } from "@solidjs/start";
import Counter from "~/components/Counter";
const BreaksOnServer = clientOnly(() => import("~/components/BreaksOnServer"));

async function hello(name: string) {
const hello = GET(async (name: string) => {
"use server";
return json(
{ hello: new Promise<string>(r => setTimeout(() => r(name), 1000)) },
{ headers: { "cache-control": "max-age=60" } }
);
}
});

export default function Home() {
GET(hello, "John").then(async v => {
hello("John").then(async v => {
console.log(v);
console.log(await v.hello);
});
Expand Down
1 change: 1 addition & 0 deletions packages/start/config/server-runtime.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ async function fetchServerFunction(base, id, method, args) {

export function createServerReference(fn, id, name) {
const baseURL = import.meta.env.SERVER_BASE_URL;
if (typeof fn !== "function") throw new Error("Export from a 'use server' module must be a function");
return new Proxy(fn, {
get(target, prop, receiver) {
if (prop === "url") {
Expand Down
6 changes: 4 additions & 2 deletions packages/start/shared/GET.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export function GET<T extends (...args: any[]) => any>(fn: T, ...args: Parameters<T>) {
return (fn as any).GET(...args) as ReturnType<T>;
export function GET<T extends (...args: any[]) => any>(fn: T) {
return (...args: Parameters<T>) => {
return (fn as any).GET(...args) as ReturnType<T>;
};
}

0 comments on commit 27d60cd

Please sign in to comment.