Created
March 26, 2015 00:33
-
-
Save aaronpowell/c5700b3d4f1612fc6df5 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
var UserList = React.createClass({ | |
render() { | |
return ( | |
<table> | |
<thead> | |
<tr> | |
<th>Name</th> | |
<th></th> | |
</tr> | |
</thead> | |
<tbody> | |
{this.props.users.filter(user => user.enabled).map(user => <UserRow user={user} />)} | |
</tbody> | |
</table> | |
); | |
} | |
}); |
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
var UserRow = React.createClass({ | |
contextTypes: { | |
userService: React.PropTypes.object | |
}, | |
render() { | |
return ( | |
<tr> | |
<td>{this.props.user.name}</td> | |
<td><button onClick={this.disable}>Disable</td> | |
</tr> | |
); | |
}, | |
disable() { | |
this.context.userService.disable(this.props.userId); | |
} | |
}); |
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
var UserView = React.createClass({ | |
childContextTypes: { | |
userStore: React.PropTypes.shape({ | |
disable: React.PropTypes.func | |
}) | |
}, | |
getInitialState() { | |
return { | |
users: [] | |
} | |
}, | |
getChildContext() { | |
return { | |
userStore: { | |
disable: userId => | |
xhr.post(`/api/user/${userId}/disable`) | |
.then(() => xhr.get(`/api/user`)) | |
.then(users => this.setState({ users })); | |
} | |
}; | |
}, | |
render() { | |
return ( | |
<UserList users={this.state.users} /> | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment