Created
August 17, 2015 17:10
-
-
Save gregturn/b4d561651b6997659786 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
| render: function () { | |
| var employees = this.props.employees.map(employee => | |
| client({method: 'GET', path: employee._links.self.href}).then(response => | |
| <Employee key={response.entity._links.self.href} | |
| headers={response.headers} | |
| employee={response.entity} | |
| attributes={this.props.attributes} | |
| onUpdate={this.props.onUpdate} | |
| onDelete={this.props.onDelete}/> | |
| ) | |
| ); | |
| console.log(employees); | |
| var the_results = when.all(employees).then(results => { | |
| /* I got results right here */ | |
| }); | |
| var navLinks = []; | |
| if ("first" in this.props.links) { | |
| navLinks.push(<button key="first" onClick={this.handleNavFirst}><<</button>); | |
| } | |
| if ("prev" in this.props.links) { | |
| navLinks.push(<button key="prev" onClick={this.handleNavPrev}><</button>); | |
| } | |
| if ("next" in this.props.links) { | |
| navLinks.push(<button key="next" onClick={this.handleNavNext}>></button>); | |
| } | |
| if ("last" in this.props.links) { | |
| navLinks.push(<button key="last" onClick={this.handleNavLast}>>></button>); | |
| } | |
| return ( | |
| <div> | |
| <input ref="pageSize" defaultValue={this.props.pageSize} onInput={this.handleInput}/> | |
| <table> | |
| <tr> | |
| <th>First Name</th> | |
| <th>Last Name</th> | |
| <th>Description</th> | |
| <th></th> | |
| </tr> | |
| {employees} | |
| </table> | |
| <div> | |
| {navLinks} | |
| </div> | |
| </div> | |
| ) | |
| } |
Author
Ahh. Maybe this.setState({/* fetched data*/}) once the data is fetched would the reactive way to go.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can't expect to be able to "extract" a value synchronously from inside the promise there, since the value might only exist in the future (and there's no blocking in JS). I think the right thing to do is fetch the employees somewhere else (not in render) and cache them. Then, implement render simply to render whatever is cached, or some default view (or empty list of employees) if the employees haven't been fetched at all yet.
Does that make sense?