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

Feature/tutorial setup#4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ShMcK merged 12 commits intomasterfromfeature/tutorial-setup
Jun 9, 2019
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
setup cond rendering route
  • Loading branch information
@ShMcK
ShMcK committedJun 9, 2019
commit864a26ed7732f8ad05c2c7a692d2db820d09f5f5
13 changes: 12 additions & 1 deletionweb-app/src/Routes.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
import * as React from 'react'
import * as CR from 'typings'
import NewPage from './components/New'
import ContinuePage from './components/Continue'
import Cond from './components/Cond'

interface ReceivedEvent {
data: CR.Action
Expand All@@ -24,8 +27,16 @@ const Routes = () => {
window.removeEventListener(listener, handleEvent)
}
})

return (
<div>State: {JSON.stringify(state)}</div>
<div>
<Cond state={state} path="SelectTutorial.NewTutorial">
<NewPage onNew={() => console.log('new!')} />
</Cond>
<Cond state={state} path="SelectTutorial.ContinueTutorial">
<ContinuePage onContinue={() => console.log('continue!')} tutorials={[]} />
</Cond>
</div>
)
}

Expand Down
17 changes: 17 additions & 0 deletionsweb-app/src/components/Cond/index.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
import * as React from 'react'
import { stateMatch } from './utils/state'

interface Props {
state: any
path: string
children: React.ReactElement
}

const Cond = (props: Props) => {
if (!stateMatch(props.state, props.path)) {
return null
}
return props.children
}

export default Cond
12 changes: 12 additions & 0 deletionsweb-app/src/components/Cond/utils/state.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
export function stateMatch(state: any, statePath: string) {
let current = state
let paths = statePath.split('.')
try {
for (const p of paths) {
current = current[p]
}
} catch (error) {
return false
}
return current !== undefined
}

[8]ページ先頭

©2009-2025 Movatter.jp