rsf-zero 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +35 -42
  2. package/package.json +10 -2
package/README.md CHANGED
@@ -1,56 +1,49 @@
1
- # rsf-zero
1
+ # RSF Zero
2
2
 
3
- ## Setup
3
+ A minimal micro-framework with React Server Functions support.
4
4
 
5
- Add these scripts to your **package.json**:
5
+ ## Installation
6
6
 
7
- ```
8
- ...
9
- "scripts": {
10
- "dev": "rsf-zero dev",
11
- "build": "rsf-zero build",
12
- "start": "rsf-zero start",
13
- },
14
- ...
7
+ ```bash
8
+ yarn add rsf-zero
9
+ # or
10
+ pnpm add rsf-zero
11
+ # or
12
+ npm install rsf-zero
15
13
  ```
16
14
 
17
- Then create an **index.html**:
18
- ```html
19
- <!doctype html>
20
- <html lang="en">
21
- <head>
22
- <meta charset="UTF-8" />
23
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
24
- <title>RSF-Zero example</title>
25
- </head>
26
- <body>
27
- <div id="root"></div>
28
- <script type="module" src="/src/main.tsx"></script>
29
- </body>
30
- </html>
31
- ```
15
+ Then follow [setup](docs/setup.md#Setup).
16
+
17
+ ## Quick intro to Server Functions
18
+ React Server Functions allow you to mark functions to run on the server:
32
19
 
33
- And finally create a **src/main.tsx** file:
34
20
  ```tsx
35
- import { StrictMode } from "react";
36
- import { createRoot } from "react-dom/client";
37
-
38
- createRoot(document.getElementById("root")!).render(
39
- <StrictMode>
40
- RSF Zero up and running!
41
- </StrictMode>,
42
- );
21
+ 'use server';
22
+
23
+ // Server function
24
+ export const addComment = async (comment: Comment) => {
25
+ await db.comment.create(comment);
26
+ }
43
27
  ```
44
28
 
29
+ ```tsx
30
+ import { addComment } from './addComment.ts';
31
+
32
+ export const AddCommentButton = (comment: Comment) =>
33
+ <Button onClick={() => addComment(comment)} />
34
+ ```
45
35
 
46
- ## Advanced topics
36
+ ### More examples
37
+ See [/example/src/App.tsx](example/src/App.tsx).
47
38
 
48
- ### Server function arguments
39
+ ### Reference Docs
40
+ - [React Server Functions](https://react.dev/reference/rsc/server-functions)
41
+ - Note: only the top-level `'use server'` is implemented by this framework.
49
42
 
50
- Server function calls are serialised and deserialised between client and server. Server function argument types must be serialisable.
43
+ ## Motivation
51
44
 
52
- **RSF Zero** uses [superjson](https://github.com/flightcontrolhq/superjson) under the hood, and the most common types are supported.
53
- See the [superjson docs](https://github.com/flightcontrolhq/superjson?tab=readme-ov-file#parse) for more info.
45
+ **RSF Zero** is designed to be a dead simple micro-framework.
54
46
 
55
- ### Verbose logging
56
- Prefix commands with `NODE_DEBUG=rsf-zero` to see debug logs, for example: `NODE_DEBUG=rsf-zero yarn build`.
47
+ 🕊 **Minimal**: Add whatever you want on top, nothing bundled that you don't use\
48
+ 🕊 **Simple**: Add `'use server'` to run something on the server, and you're done, nothing new to learn\
49
+ 🕊️ **Done**: Instead, spend your spare time sipping a nice coffee or looking at a bird
package/package.json CHANGED
@@ -1,11 +1,19 @@
1
1
  {
2
2
  "name": "rsf-zero",
3
+ "description": "A minimal micro-framework with React Server Functions support",
4
+ "author": "Igor Nadj",
3
5
  "type": "module",
4
- "version": "0.1.0",
6
+ "version": "0.1.2",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/IgorNadj/rsf-zero.git",
10
+ "directory": "rsf-zero"
11
+ },
5
12
  "scripts": {
6
13
  "build": "rm -rf ./dist && tsc",
7
14
  "test": "vitest run",
8
- "test:watch": "vitest"
15
+ "test:watch": "vitest",
16
+ "publish": "npm run build && npm run test && cp ../README.md . && npm publish"
9
17
  },
10
18
  "dependencies": {
11
19
  "@swc/core": "^1.12.1",