Skip to content

Instantly share code, notes, and snippets.

@joynal
Last active July 13, 2016 05:53
Show Gist options
  • Save joynal/fd55e1284504187774514e898b0990c1 to your computer and use it in GitHub Desktop.
Save joynal/fd55e1284504187774514e898b0990c1 to your computer and use it in GitHub Desktop.
class Person{
@observable firstName = 'David';
@observable lastName = 'Khan';
@observable age = 23;
@computed fullName(){
return firstName + ' ' + lastName;
}
@action changeName(firstName, lastName){
this.firstName = firstName;
this.lastName = firstName;
}
}
mobx.autorun(() => {
console.log(obj.fullName);
});
let obj = new Person();
obj.changeName('Suzon', 'Zahid');
// David khan
// Suzon Zahid
import React, {Component} from 'react';
import {render} from 'react-dom';
@observer
class PersonView extends Component{
render(){
setTimeout(this.props.person.changeName('Joynal', 'Abedin'), 5000);
return (
<h1>{this.props.person.firstName} {this.props.person.lastName}<h1>
);
}
}
render(
<PersonView person={new Person}/>,
document.getElementById('app');
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment