-
-
Save Yang03/1b47123243433c7c9a00f15728052624 to your computer and use it in GitHub Desktop.
This file contains 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
const {observable, computed} = mobx; | |
const {observer} = mobxReact; | |
const {Component} = React; | |
class Message { | |
@observable title; | |
@observable likes = []; | |
@observable author = {}; | |
} | |
@observer | |
class View extends Component { | |
render() { | |
const message = this.props.message | |
return ( | |
<div> | |
{message.title} | |
<Author author={message.author}/> | |
<Likes likes={message.likes}/> | |
</div> | |
) | |
} | |
} | |
class Author extends Component { | |
render() { | |
const author = this.props.author | |
return ( | |
<span>{author.name}</span> | |
) | |
} | |
} | |
class Likes extends Component { | |
render() { | |
const likes = this.props.likes || [] | |
console.log(likes.slice()) | |
return (<ul>{ | |
likes.map(like => <li>{like}</li>) | |
}</ul>) | |
} | |
} | |
const store = new Message(); | |
ReactDOM.render(<View message={store} />, document.getElementById('mount')); | |
store.title = 'a' | |
store.author = { | |
name: 'ab' | |
} | |
//store.likes = [1,2,3,4,5] | |
store.likes.push(1) | |
store.likes.push(2) | |
window.store = store; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://jsfiddle.net/wv3yopo0/1270/