File tree Expand file tree Collapse file tree 3 files changed +41
-1
lines changed Expand file tree Collapse file tree 3 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 11import * as React from 'react'
22import * as CR from 'typings'
3+ import NewPage from './components/New'
4+ import ContinuePage from './components/Continue'
5+ import Cond from './components/Cond'
36
47interface ReceivedEvent {
58 data : CR . Action
@@ -24,8 +27,16 @@ const Routes = () => {
2427 window . removeEventListener ( listener , handleEvent )
2528 }
2629 } )
30+
2731 return (
28- < div > State: { JSON . stringify ( state ) } </ div >
32+ < div >
33+ < Cond state = { state } path = "SelectTutorial.NewTutorial" >
34+ < NewPage onNew = { ( ) => console . log ( 'new!' ) } />
35+ </ Cond >
36+ < Cond state = { state } path = "SelectTutorial.ContinueTutorial" >
37+ < ContinuePage onContinue = { ( ) => console . log ( 'continue!' ) } tutorials = { [ ] } />
38+ </ Cond >
39+ </ div >
2940 )
3041}
3142
Original file line number Diff line number Diff line change 1+ import * as React from 'react'
2+ import { stateMatch } from './utils/state'
3+
4+ interface Props {
5+ state : any
6+ path : string
7+ children : React . ReactElement
8+ }
9+
10+ const Cond = ( props : Props ) => {
11+ if ( ! stateMatch ( props . state , props . path ) ) {
12+ return null
13+ }
14+ return props . children
15+ }
16+
17+ export default Cond
Original file line number Diff line number Diff line change 1+ export function stateMatch ( state : any , statePath : string ) {
2+ let current = state
3+ let paths = statePath . split ( '.' )
4+ try {
5+ for ( const p of paths ) {
6+ current = current [ p ]
7+ }
8+ } catch ( error ) {
9+ return false
10+ }
11+ return current !== undefined
12+ }
You can’t perform that action at this time.
0 commit comments