Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0b9ba41

Browse files
committed
cleanup new router
1 parent8bafa1f commit0b9ba41

File tree

10 files changed

+32
-66
lines changed

10 files changed

+32
-66
lines changed

‎web-app/package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎web-app/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"dependencies": {
2929
"@alifd/next":"^1.17.7",
3030
"@apollo/react-hooks":"^3.0.1",
31+
"@xstate/react":"^0.7.1",
3132
"apollo-boost":"^0.4.4",
3233
"graphql":"^14.4.2",
3334
"markdown-it":"^9.1.0",
@@ -37,7 +38,8 @@
3738
"react":"^16.9.0",
3839
"react-dom":"^16.9.0",
3940
"react-scripts":"^3.1.1",
40-
"typescript":"^3.5.3"
41+
"typescript":"^3.5.3",
42+
"xstate":"^4.6.7"
4143
},
4244
"devDependencies": {
4345
"@babel/core":"^7.5.4",

‎web-app/src/Routes.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ const Routes = ({ state }: Props) => {
4646
return(
4747
<divstyle={{ ...styles.page, ...dimensions}}>
4848
<Routerstate={state}>
49+
<Routepath="Start.Initial">
50+
<div>Initial</div>
51+
</Route>
4952
<Routepath="Start.Startup">
5053
<LoadingPagetext="Launching..."/>
5154
</Route>

‎web-app/src/components/Router/index.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
import*asReactfrom'react'
2+
import{useMachine}from'@xstate/react'
3+
importmachinefrom'../../services/state/machine'
24
importRoutefrom'./Route'
35

46
interfaceProps{
57
state:string
68
children:any
79
}
810

9-
conststateMatch=(state:string,path:string)=>{
10-
return!!(newRegExp(`^${state}`).exec(path))
11-
}
11+
//const stateMatch = (state: string, path: string) => {
12+
// return !!(new RegExp(`^${state}`).exec(path))
13+
//}
1214

1315
// router finds first state match of <Route path='' />
14-
constRouter=({ state, children}:Props)=>{
16+
constRouter=({ children}:Props)=>{
17+
const[current,send]=useMachine(machine)
18+
1519
constchildArray=React.Children.toArray(children)
1620
for(constchildofchildArray){
17-
if(stateMatch(state,child.props.path)){
18-
returnchild.props.children
21+
if(current.matches(child.props.path)){
22+
if(child.props.send){
23+
returnReact.cloneElement(child.props.children,{ send})
24+
}else{
25+
returnchild.props.children
26+
}
27+
1928
}
2029
}
21-
console.warn(`No Route matches for${JSON.stringify(state)}`)
30+
console.warn(`No Route matches for${JSON.stringify(current)}`)
2231
returnnull
2332
}
2433

‎web-app/src/state/actions/index.tsrenamed to‎web-app/src/services/state/actions/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
exportdefault{}
1010

1111
// export default {
12-
// createWebview() {
13-
// editorDispatch('coderoad.open_webview')
14-
// },
1512
// async newOrContinue() {
1613
// // verify that the user has an existing tutorial to continue
1714
// // const hasExistingTutorial: boolean = await tutorialModel.hasExisting()

‎web-app/src/state/machine.tsrenamed to‎web-app/src/services/state/machine.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export const machine = Machine<{}, CR.MachineStateSchema, CR.MachineEvent>(
1010
initial:'Start',
1111
states:{
1212
Start:{
13-
onEntry:['createWebview'],
1413
initial:'Initial',
1514
states:{
1615
Initial:{

‎web-app/src/state/index.ts

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp