~repos /edge-city
git clone https://pyrossh.dev/repos/edge-city.git
edge-city is a next level meta-framework for react that runs only on edge runtimes
3f3b9d9f
—
Peter John 2 years ago
use preact signals
- packages/example/Dockerfile +2 -0
- packages/example/package.json +1 -1
- packages/parotta/atom.js +0 -47
- packages/parotta/bun.lockb +0 -0
- packages/parotta/cli.js +4 -4
- packages/parotta/package.json +2 -2
- packages/parotta/router.js +3 -5
packages/example/Dockerfile
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
FROM oven/bun
|
|
2
2
|
|
|
3
|
+
ENV NODE_ENV production
|
|
4
|
+
|
|
3
5
|
WORKDIR /app
|
|
4
6
|
COPY . /app
|
|
5
7
|
|
packages/example/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"type": "module",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "bunx parotta",
|
|
6
|
-
"start": "
|
|
6
|
+
"start": "bunx parotta",
|
|
7
7
|
"build": "docker build . -t example",
|
|
8
8
|
"run": "docker run -p 3000:3000 example"
|
|
9
9
|
},
|
packages/parotta/atom.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react';
|
|
2
|
-
|
|
3
|
-
export const atom = (initial) => {
|
|
4
|
-
let value;
|
|
5
|
-
const isDerived = typeof initial === 'function';
|
|
6
|
-
const subs = new Set();
|
|
7
|
-
const get = (a) => {
|
|
8
|
-
a.subscribe(compute);
|
|
9
|
-
return a.getValue();
|
|
10
|
-
};
|
|
11
|
-
const compute = () => {
|
|
12
|
-
value = initial(get);
|
|
13
|
-
subs.forEach((sub) => {
|
|
14
|
-
sub(value);
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
if (isDerived) {
|
|
18
|
-
compute();
|
|
19
|
-
} else {
|
|
20
|
-
value = initial;
|
|
21
|
-
}
|
|
22
|
-
return {
|
|
23
|
-
getValue() {
|
|
24
|
-
return value;
|
|
25
|
-
},
|
|
26
|
-
subscribe(fn) {
|
|
27
|
-
subs.add(fn);
|
|
28
|
-
return () => subs.delete(fn);
|
|
29
|
-
},
|
|
30
|
-
update(fn) {
|
|
31
|
-
value = fn(value);
|
|
32
|
-
subs.forEach((sub) => {
|
|
33
|
-
sub(value);
|
|
34
|
-
});
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const useAtom = (atom) => {
|
|
40
|
-
const [data, setData] = useState(atom.getValue());
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
return atom.subscribe((value) => {
|
|
43
|
-
setData(value);
|
|
44
|
-
});
|
|
45
|
-
}, []);
|
|
46
|
-
return data;
|
|
47
|
-
};
|
packages/parotta/bun.lockb
ADDED
|
Binary file
|
packages/parotta/cli.js
CHANGED
|
@@ -10,7 +10,7 @@ import postcssNesting from "postcss-nesting";
|
|
|
10
10
|
import { renderToReadableStream } from 'react-dom/server';
|
|
11
11
|
import { createRouter } from 'radix3';
|
|
12
12
|
import mimeTypes from "mime-types";
|
|
13
|
-
import {
|
|
13
|
+
import { routerSignal } from './router.js';
|
|
14
14
|
|
|
15
15
|
console.log("running in folder:", path.basename(process.cwd()), "env:", process.env.NODE_ENV);
|
|
16
16
|
// console.log("deleting cache");
|
|
@@ -69,10 +69,10 @@ const hydrateScript = (filePath, initialRouteValue) => {
|
|
|
69
69
|
return `
|
|
70
70
|
import React from 'react';
|
|
71
71
|
import { hydrateRoot } from 'react-dom/client';
|
|
72
|
-
|
|
72
|
+
import { routerSignal } from "parotta/router";
|
|
73
73
|
import Page from "${filePath}";
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
routerSignal.value = ${JSON.stringify(initialRouteValue)};
|
|
76
76
|
|
|
77
77
|
hydrateRoot(document.getElementById("root"), React.createElement(Page, {}, undefined, false, undefined, this));
|
|
78
78
|
`;
|
|
@@ -118,7 +118,7 @@ const renderPage = async (filePath, url, params) => {
|
|
|
118
118
|
params: params,
|
|
119
119
|
pathname: url.pathname,
|
|
120
120
|
}
|
|
121
|
-
|
|
121
|
+
routerSignal.value = initialRouteValue;
|
|
122
122
|
const routeImport = await import(path.join(process.cwd(), filePath));
|
|
123
123
|
const packageJson = await import(path.join(process.cwd(), "package.json"));
|
|
124
124
|
const devTag = !isProd ? "?dev" : "";
|
packages/parotta/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "parotta",
|
|
3
3
|
"version": "0.1.0",
|
|
4
|
-
"module": "cli.js",
|
|
5
4
|
"type": "module",
|
|
6
5
|
"dependencies": {
|
|
7
6
|
"autoprefixer": "^10.4.14",
|
|
@@ -11,7 +10,8 @@
|
|
|
11
10
|
"postcss-nesting": "^11.2.1",
|
|
12
11
|
"postcss-normalize": "^10.0.1",
|
|
13
12
|
"radix3": "^1.0.0",
|
|
14
|
-
"walkdir": "0.4.1"
|
|
13
|
+
"walkdir": "0.4.1",
|
|
14
|
+
"@preact/signals-react": "1.2.2"
|
|
15
15
|
},
|
|
16
16
|
"bin": {
|
|
17
17
|
"parotta": "./cli.js"
|
packages/parotta/router.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import { signal, useSignal } from "@preact/signals-react";
|
|
2
|
-
import { createRouter } from 'radix3';
|
|
3
|
-
import { atom, useAtom } from "./atom.js";
|
|
4
2
|
|
|
5
|
-
export const
|
|
3
|
+
export const routerSignal = signal({
|
|
6
4
|
pathname: "/",
|
|
7
5
|
query: {},
|
|
8
6
|
params: {},
|
|
9
7
|
});
|
|
10
8
|
|
|
11
|
-
export const useRouter = () =>
|
|
9
|
+
export const useRouter = () => useSignal(routerSignal);
|
|
12
10
|
|
|
13
11
|
export const push = () => {
|
|
14
12
|
}
|