Skip to content

Commit

Permalink
docs(changeset): added a stacks feature to quickly build up app confi…
Browse files Browse the repository at this point in the history
…g from the CLI (experimental)
  • Loading branch information
nksaraf committed Nov 4, 2023
1 parent 0cc2f4a commit b0029a2
Show file tree
Hide file tree
Showing 45 changed files with 542 additions and 167 deletions.
8 changes: 8 additions & 0 deletions .changeset/eleven-birds-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@vinxi/server-components": patch
"@vinxi/server-functions": patch
"@vinxi/plugin-directives": patch
"vinxi": patch
---

added a stacks feature to quickly build up app config from the CLI (experimental)
24 changes: 12 additions & 12 deletions examples/react/rsc/spa/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

- Updated dependencies [978b04a]
- vinxi@0.0.43
- @vinxi/plugin-server-components@0.0.35
- @vinxi/plugin-server-functions@0.0.35
- @vinxi/server-components@0.0.35
- @vinxi/server-functions@0.0.35

## null

Expand All @@ -16,26 +16,26 @@
- Updated dependencies [e8fdad4]
- Updated dependencies [291a5cf]
- vinxi@0.0.42
- @vinxi/plugin-server-components@0.0.34
- @vinxi/plugin-server-functions@0.0.34
- @vinxi/server-components@0.0.34
- @vinxi/server-functions@0.0.34

## null

### Patch Changes

- Updated dependencies [2e52d87]
- @vinxi/plugin-server-functions@0.0.33
- @vinxi/server-functions@0.0.33
- vinxi@0.0.41
- @vinxi/plugin-server-components@0.0.33
- @vinxi/server-components@0.0.33

## null

### Patch Changes

- Updated dependencies [0335776]
- @vinxi/plugin-server-components@0.0.32
- @vinxi/server-components@0.0.32
- vinxi@0.0.40
- @vinxi/plugin-server-functions@0.0.32
- @vinxi/server-functions@0.0.32

## null

Expand All @@ -44,18 +44,18 @@
- Updated dependencies [f237894]
- Updated dependencies [d620072]
- vinxi@0.0.39
- @vinxi/plugin-server-components@0.0.31
- @vinxi/plugin-server-functions@0.0.31
- @vinxi/server-components@0.0.31
- @vinxi/server-functions@0.0.31

## null

### Patch Changes

- Updated dependencies [1284791]
- Updated dependencies [930b2f2]
- @vinxi/plugin-server-functions@0.0.30
- @vinxi/server-functions@0.0.30
- vinxi@0.0.38
- @vinxi/plugin-server-components@0.0.30
- @vinxi/server-components@0.0.30

## null

Expand Down
4 changes: 2 additions & 2 deletions examples/react/rsc/spa/app.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { serverComponents } from "@vinxi/plugin-server-components";
import { serverFunctions } from "@vinxi/plugin-server-functions";
import { serverComponents } from "@vinxi/server-components/plugin";
import { serverFunctions } from "@vinxi/server-functions/plugin";
import reactRefresh from "@vitejs/plugin-react";
import { createApp } from "vinxi";

Expand Down
31 changes: 16 additions & 15 deletions examples/react/rsc/spa/app/server-action.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { eventHandler, readRawBody, setHeader } from "vinxi/server";
import { eventHandler, sendStream } from "vinxi/server";

export default eventHandler(async (event) => {
if (event.method === "POST") {
if (event.node.req.method === "POST") {
const {
renderToPipeableStream,
decodeReply,
decodeReplyFromBusboy,
decodeAction,
} = await import("@vinxi/react-server-dom/server");
const serverReference = event.headers.get("server-action");
const serverReference = event.node.req.headers["server-action"];
if (serverReference) {
// This is the client-side case
const [filepath, name] = serverReference.split("#");
const action = (
await import.meta.env.MANIFEST["server"].chunks[filepath].import()
await import.meta.env.MANIFEST["rsc"].chunks[filepath].import()
)[name];
// Validate that this is actually a function we intended to expose and
// not the client trying to invoke arbitrary functions. In a real app,
Expand All @@ -23,14 +23,16 @@ export default eventHandler(async (event) => {
}

let args;
// if (req.is('multipart/form-data')) {
// // Use busboy to streamingly parse the reply from form-data.
// const bb = busboy({headers: req.headers});
// const reply = decodeReplyFromBusboy(bb, moduleBasePath);
// req.pipe(bb);
// args = await reply;
// } else {
const text = await readRawBody(event);
const text = await new Promise((resolve) => {
const requestBody = [];
event.node.req.on("data", (chunks) => {
console.log(chunks);
requestBody.push(chunks);
});
event.node.req.on("end", () => {
resolve(requestBody.join(""));
});
});
console.log(text);

args = await decodeReply(text);
Expand All @@ -50,12 +52,11 @@ export default eventHandler(async (event) => {
events[event] = listener;
};

setHeader(event, "Content-Type", "application/json");
setHeader(event, "Router", "server");
event.node.res.setHeader("Content-Type", "application/json");
event.node.res.setHeader("Router", "server");

return stream;
} catch (x) {
console.error(x);
// We handle the error on the client
}
// Refresh the client and return the value
Expand Down
4 changes: 2 additions & 2 deletions examples/react/rsc/spa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
},
"dependencies": {
"@picocss/pico": "^1.5.10",
"@vinxi/plugin-server-components": "0.0.35",
"@vinxi/plugin-server-functions": "0.0.35",
"@vinxi/server-components": "0.0.35",
"@vinxi/server-functions": "0.0.35",
"@vinxi/react": "0.0.11",
"@vinxi/react-server-dom": "0.0.3",
"@vitejs/plugin-react": "^4.0.4",
Expand Down
2 changes: 1 addition & 1 deletion examples/react/rsc/spa/tmp/count
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8
20
3 changes: 1 addition & 2 deletions examples/vanilla/spa/app.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { serverFunctions } from "@vinxi/plugin-server-functions";
import { serverFunctions } from "@vinxi/server-functions/plugin";
import { createApp } from "vinxi";

export default createApp({
Expand All @@ -12,7 +12,6 @@ export default createApp({
name: "client",
mode: "spa",
handler: "./index.html",
target: "browser",
plugins: () => [serverFunctions.client()],
},
serverFunctions.router({
Expand Down
6 changes: 6 additions & 0 deletions examples/vanilla/spa/app/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ const world4 = async (x, y) => {
console.log("hello world 4", x, y);
};

const world5 = async (x) => {
"use server";
console.log("hello world 4", x);
};

console.log(
await world(),
await world2(1),
await world3(2, 3),
await world4(5, 6),
await sayHello(),
await world5({ hello: 1, world: "aasd", x: true }),
);
console.log("Hello world!");

Expand Down
2 changes: 1 addition & 1 deletion examples/vanilla/spa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"@picocss/pico": "^1.5.10",
"@vinxi/plugin-server-functions": "workspace:^",
"@vinxi/server-functions": "0.0.35",
"autoprefixer": "^10.4.15",
"tailwindcss": "^3.3.3",
"vinxi": "0.0.43"
Expand Down
1 change: 1 addition & 0 deletions examples/vanilla/stack/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vercel
104 changes: 104 additions & 0 deletions examples/vanilla/stack/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# example-vanilla

## null

### Patch Changes

- Updated dependencies [355daea]
- @vinxi/plugin-references@0.0.24
- vinxi@0.0.34

## null

### Patch Changes

- Updated dependencies [1dec590]
- vinxi@0.0.33
- @vinxi/plugin-references@0.0.23

## null

### Patch Changes

- Updated dependencies [982147a]
- vinxi@0.0.32
- @vinxi/plugin-references@0.0.22

## null

### Patch Changes

- Updated dependencies [94f59aa]
- Updated dependencies [bc82d8e]
- Updated dependencies [1d8b542]
- Updated dependencies [5bf5e03]
- Updated dependencies [4c7fd35]
- Updated dependencies [0f4b3ee]
- Updated dependencies [ad62318]
- Updated dependencies [c223ab6]
- Updated dependencies [94f59aa]
- @vinxi/plugin-references@0.0.21
- vinxi@0.0.31

## null

### Patch Changes

- Updated dependencies [fd06048]
- Updated dependencies [0f14555]
- Updated dependencies [82267c5]
- vinxi@0.0.30
- @vinxi/plugin-references@0.0.20

## null

### Patch Changes

- Updated dependencies [8058084]
- vinxi@0.0.29
- @vinxi/plugin-references@0.0.19

## null

### Patch Changes

- Updated dependencies [b934e84]
- Updated dependencies [17693dc]
- Updated dependencies [d6305b8]
- Updated dependencies [cb91c48]
- Updated dependencies [085116d]
- Updated dependencies [f1ee5b8]
- vinxi@0.0.28
- @vinxi/plugin-references@0.0.18

## null

### Patch Changes

- Updated dependencies [7803042]
- vinxi@0.0.27
- @vinxi/plugin-references@0.0.17

## null

### Patch Changes

- Updated dependencies [2b17e0d]
- vinxi@0.0.26
- @vinxi/plugin-references@0.0.16

## null

### Patch Changes

- Updated dependencies [552d8ca]
- vinxi@0.0.25
- @vinxi/plugin-references@0.0.15

## null

### Patch Changes

- Updated dependencies [47abc3c]
- @vinxi/plugin-references@0.0.14
- vinxi@0.0.24
12 changes: 12 additions & 0 deletions examples/vanilla/stack/app/actions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use server";

let store = { count: 0 };
export function sayHello() {
console.log("Hello World");
store.count++;
return store.count;
}

export function getStore() {
return store.count;
}
38 changes: 38 additions & 0 deletions examples/vanilla/stack/app/client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/// <reference types="vinxi/types/client" />
import "vinxi/client";

import { sayHello } from "./actions";
import { world } from "./server-functions";
import "./style.css";

export async function world2(x) {
"use server";
console.log("hello world 2", x);
}

async function world3(x, y) {
"use server";
console.log("hello world 3", x, y);
}

const world4 = async (x, y) => {
"use server";
console.log("hello world 4", x, y);
};

const world5 = async (x) => {
"use server";
console.log("hello world 4", x);
};

console.log(
await world(),
await world2(1),
await world3(2, 3),
await world4(5, 6),
await sayHello(),
await world5({ hello: 1, world: "aasd", x: true }),
);
console.log("Hello world!");

document.getElementById("app").innerHTML = `Hello World`;
10 changes: 10 additions & 0 deletions examples/vanilla/stack/app/middleware.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineMiddleware, getContext, setContext } from "vinxi/server";

export default defineMiddleware({
onRequest: (event) => {
setContext(event, "help", { foo: "bar" });
},
onBeforeResponse: (event) => {
console.log(getContext(event, "help"));
},
});
4 changes: 4 additions & 0 deletions examples/vanilla/stack/app/server-functions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export async function world() {
"use server";
console.log("hello");
}
7 changes: 7 additions & 0 deletions examples/vanilla/stack/app/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

* {
color: red;
}
Loading

0 comments on commit b0029a2

Please sign in to comment.