Created
March 26, 2015 00:33
-
-
Save aaronpowell/c5700b3d4f1612fc6df5 to your computer and use it in GitHub Desktop.
Revisions
-
aaronpowell created this gist
Mar 26, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ 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} /> ); } });