~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
e643f73f
—
Peter John 2 years ago
v0.2.0
- packages/parotta/bun.lockb +0 -0
- packages/parotta/error.js +42 -0
- packages/parotta/package.json +2 -3
- packages/parotta/router.js +32 -22
packages/parotta/bun.lockb
CHANGED
|
Binary file
|
packages/parotta/error.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
const changedArray = (a = [], b = []) =>
|
|
4
|
+
a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]))
|
|
5
|
+
|
|
6
|
+
export class ErrorBoundary extends React.Component {
|
|
7
|
+
// static propTypes = {
|
|
8
|
+
// resetKeys: PropTypes.arrayOf(PropTypes.any),
|
|
9
|
+
// }
|
|
10
|
+
static getDerivedStateFromError(error) {
|
|
11
|
+
return { error }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
state = {}
|
|
15
|
+
|
|
16
|
+
componentDidCatch(error, info) {
|
|
17
|
+
this.props.onError?.(error, info)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
componentDidUpdate(prevProps, prevState) {
|
|
21
|
+
const { error } = this.state
|
|
22
|
+
const { resetKeys } = this.props
|
|
23
|
+
if (
|
|
24
|
+
error !== null &&
|
|
25
|
+
prevState.error !== null &&
|
|
26
|
+
changedArray(prevProps.resetKeys, resetKeys)
|
|
27
|
+
) {
|
|
28
|
+
this.setState({});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
render() {
|
|
33
|
+
const { error } = this.state;
|
|
34
|
+
const { children, fallback } = this.props;
|
|
35
|
+
if (error) {
|
|
36
|
+
if (React.isValidElement(fallback)) {
|
|
37
|
+
return fallback;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return children;
|
|
41
|
+
}
|
|
42
|
+
}
|
packages/parotta/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "parotta",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"autoprefixer": "^10.4.14",
|
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
"postcss-nesting": "^11.2.1",
|
|
11
11
|
"postcss-normalize": "^10.0.1",
|
|
12
12
|
"radix3": "^1.0.0",
|
|
13
|
-
"walkdir": "0.4.1"
|
|
13
|
+
"walkdir": "0.4.1"
|
|
14
|
-
"@preact/signals-react": "1.2.2"
|
|
15
14
|
},
|
|
16
15
|
"bin": {
|
|
17
16
|
"parotta": "./cli.js"
|
packages/parotta/router.js
CHANGED
|
@@ -1,26 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
-
export const
|
|
3
|
+
export const RouterContext = createContext({
|
|
4
|
+
stack: [],
|
|
5
|
+
state: {
|
|
4
|
-
|
|
6
|
+
pathname: "",
|
|
5
|
-
|
|
7
|
+
query: {},
|
|
6
|
-
|
|
8
|
+
params: {},
|
|
9
|
+
}
|
|
7
10
|
});
|
|
8
11
|
|
|
9
|
-
export const useRouter = () => useSignal(routerSignal);
|
|
10
|
-
|
|
11
|
-
export const push = () => {
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const replace = () => {
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const prefetch = () => {
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const
|
|
12
|
+
export const RouterProvider = ({ value, children }) => {
|
|
13
|
+
return (
|
|
14
|
+
<RouterContext.Provider value={value}>
|
|
21
|
-
}
|
|
15
|
+
{children}
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
</RouterContext.Provider>
|
|
17
|
+
)
|
|
24
18
|
}
|
|
25
19
|
|
|
20
|
+
export const useRouter = () => {
|
|
21
|
+
const ctx = useContext(RouterContext);
|
|
22
|
+
return {
|
|
23
|
+
...ctx.state,
|
|
24
|
+
push: (path) => {
|
|
25
|
+
},
|
|
26
|
+
replace: (path) => {
|
|
27
|
+
},
|
|
28
|
+
prefetch: () => {
|
|
29
|
+
},
|
|
30
|
+
beforePopState: () => {
|
|
31
|
+
},
|
|
32
|
+
back: () => {
|
|
33
|
+
},
|
|
26
|
-
|
|
34
|
+
reload: () => window.location.reload(),
|
|
35
|
+
};
|
|
36
|
+
}
|