Last active
August 8, 2018 04:06
-
-
Save drzhbe/621b669469172e2d2d2080e25304ce37 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
type Store = { treasure: number }; | |
type Presenter = { digTreasure: (store: Store, place: string) => void }; | |
type MyCompo1Props = { store: Store, presenter: Presenter }; | |
class MyCompo1 extends React.Component<MyCompo1Props> { | |
render() { | |
/* should be an error because `this` in `digTreasure` will be not as expected */ | |
return <MyCompo2 onDig={this.digTreasure}/>; | |
} | |
digTreasure(place: string) { | |
const { presenter, store } = this.props; | |
presenter.digTreasure(store, place); | |
} | |
} | |
type MyCompo2Props = { onDig: (place: string) => void }; | |
class MyCompo2 extends React.Component<MyCompo2Props> { | |
render() { | |
return <> | |
<div onClick={() => this.props.onDig('palm')}>Dig under the palm</div> | |
<div onClick={() => this.props.onDig('beach')}>Dig on the beach</div> | |
</>; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment