|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var React = require('react'); |
| 4 | +var ReactDOM = require('react-dom'); |
| 5 | +const {Row} = require('./Row'); |
| 6 | +const {Store} = require('./Store'); |
| 7 | + |
| 8 | +var startTime; |
| 9 | +var lastMeasure; |
| 10 | +var startMeasure = function(name) { |
| 11 | + startTime = performance.now(); |
| 12 | + lastMeasure = name; |
| 13 | +} |
| 14 | +var stopMeasure = function() { |
| 15 | + var last = lastMeasure; |
| 16 | + if (lastMeasure) { |
| 17 | + window.setTimeout(function () { |
| 18 | + lastMeasure = null; |
| 19 | + var stop = performance.now(); |
| 20 | + var duration = 0; |
| 21 | + console.log(last+" took "+(stop-startTime)); |
| 22 | + }, 0); |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +export class Main extends React.Component{ |
| 27 | + constructor(props) { |
| 28 | + super(props); |
| 29 | + this.state = {store: new Store()}; |
| 30 | + this.select = this.select.bind(this); |
| 31 | + this.delete = this.delete.bind(this); |
| 32 | + this.add = this.add.bind(this); |
| 33 | + this.run = this.run.bind(this); |
| 34 | + this.update = this.update.bind(this); |
| 35 | + this.runLots = this.runLots.bind(this); |
| 36 | + this.clear = this.clear.bind(this); |
| 37 | + this.swapRows = this.swapRows.bind(this); |
| 38 | + this.start = 0; |
| 39 | + } |
| 40 | + printDuration() { |
| 41 | + stopMeasure(); |
| 42 | + } |
| 43 | + componentDidUpdate() { |
| 44 | + this.printDuration(); |
| 45 | + } |
| 46 | + componentDidMount() { |
| 47 | + this.printDuration(); |
| 48 | + } |
| 49 | + run() { |
| 50 | + startMeasure("run"); |
| 51 | + this.state.store.run(); |
| 52 | + this.setState({store: this.state.store}); |
| 53 | + } |
| 54 | + add() { |
| 55 | + startMeasure("add"); |
| 56 | + this.state.store.add(); |
| 57 | + this.setState({store: this.state.store}); |
| 58 | + } |
| 59 | + update() { |
| 60 | + startMeasure("update"); |
| 61 | + this.state.store.update(); |
| 62 | + this.setState({store: this.state.store}); |
| 63 | + } |
| 64 | + select(id) { |
| 65 | + startMeasure("select"); |
| 66 | + this.state.store.select(id); |
| 67 | + this.setState({store: this.state.store}); |
| 68 | + } |
| 69 | + delete(id) { |
| 70 | + startMeasure("delete"); |
| 71 | + this.state.store.delete(id); |
| 72 | + this.setState({store: this.state.store}); |
| 73 | + } |
| 74 | + runLots() { |
| 75 | + startMeasure("runLots"); |
| 76 | + this.state.store.runLots(); |
| 77 | + this.setState({store: this.state.store}); |
| 78 | + } |
| 79 | + clear() { |
| 80 | + startMeasure("clear"); |
| 81 | + this.state.store.clear(); |
| 82 | + this.setState({store: this.state.store}); |
| 83 | + } |
| 84 | + swapRows() { |
| 85 | + startMeasure("swapRows"); |
| 86 | + this.state.store.swapRows(); |
| 87 | + this.setState({store: this.state.store}); |
| 88 | + } |
| 89 | + render () { |
| 90 | + let rows = this.state.store.data.map((d,i) => { |
| 91 | + return <Row key={i} data={d} onClick={this.select} onDelete={this.delete} styleClass={d.id === this.state.store.selected ? 'danger':''}></Row> |
| 92 | + }); |
| 93 | + return (<div className="container"> |
| 94 | + <div className="jumbotron"> |
| 95 | + <div className="row"> |
| 96 | + <div className="col-md-6"> |
| 97 | + <h1>React v15.4.2 (non-keyed)</h1> |
| 98 | + </div> |
| 99 | + <div className="col-md-6"> |
| 100 | + <div className="row"> |
| 101 | + <div className="col-sm-6 smallpad"> |
| 102 | + <button type="button" className="btn btn-primary btn-block" id="run" onClick={this.run}>Create 1,000 rows</button> |
| 103 | + </div> |
| 104 | + <div className="col-sm-6 smallpad"> |
| 105 | + <button type="button" className="btn btn-primary btn-block" id="runlots" onClick={this.runLots}>Create 10,000 rows</button> |
| 106 | + </div> |
| 107 | + <div className="col-sm-6 smallpad"> |
| 108 | + <button type="button" className="btn btn-primary btn-block" id="add" onClick={this.add}>Append 1,000 rows</button> |
| 109 | + </div> |
| 110 | + <div className="col-sm-6 smallpad"> |
| 111 | + <button type="button" className="btn btn-primary btn-block" id="update" onClick={this.update}>Update every 10th row</button> |
| 112 | + </div> |
| 113 | + <div className="col-sm-6 smallpad"> |
| 114 | + <button type="button" className="btn btn-primary btn-block" id="clear" onClick={this.clear}>Clear</button> |
| 115 | + </div> |
| 116 | + <div className="col-sm-6 smallpad"> |
| 117 | + <button type="button" className="btn btn-primary btn-block" id="swaprows" onClick={this.swapRows}>Swap Rows</button> |
| 118 | + </div> |
| 119 | + </div> |
| 120 | + </div> |
| 121 | + </div> |
| 122 | + </div> |
| 123 | + <table className="table table-hover table-striped test-data"> |
| 124 | + <tbody> |
| 125 | + {rows} |
| 126 | + </tbody> |
| 127 | + </table> |
| 128 | + <span className="preloadicon glyphicon glyphicon-remove" aria-hidden="true"></span> |
| 129 | + </div>); |
| 130 | + } |
| 131 | +} |
0 commit comments