Skip to content

Commit d2155b1

Browse files
committed
fix race condition for sorting (hopefully)
1 parent 4764d58 commit d2155b1

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/Stocks.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,18 @@ class Stocks extends Component {
2121
this.fetches = setInterval(this.getStocks, 5000);
2222
}
2323

24-
fetchStock = index => {
24+
fetchStock = s => {
2525
let url = '/api/stock';
2626
$.ajax({
2727
url: url,
2828
data: {
29-
symbol: this.state.stocks[index].symbol
29+
symbol: s.symbol
3030
},
3131
type: 'GET',
3232
success: stock => {
3333
let temp = this.state.stocks;
34-
if (temp[index].symbol === this.state.stocks[index].symbol) {
35-
Object.assign(temp[index], stock);
36-
this.setState({ stocks: temp });
37-
}
34+
Object.assign(s, stock);
35+
this.setState({ stocks: temp });
3836
},
3937
error: (xhr, status, err) => {
4038
console.error(url, status, err.toString());
@@ -44,7 +42,7 @@ class Stocks extends Component {
4442

4543
getStocks = () => {
4644
for (let i = 0; i < this.state.stocks.length; i++) {
47-
this.fetchStock(i);
45+
this.fetchStock(this.state.stocks[i]);
4846
}
4947
};
5048

0 commit comments

Comments
 (0)