Skip to content

Instantly share code, notes, and snippets.

@Yang03 Yang03/mobx
Created Jun 6, 2017

Embed
What would you like to do?
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;
@Yang03

This comment has been minimized.

Copy link
Owner Author

Yang03 commented Jun 6, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.