Skip to content

Commit

Permalink
fix: history object reference
Browse files Browse the repository at this point in the history
  • Loading branch information
dsrkafuu committed Mar 18, 2022
1 parent 4de1694 commit 325fa0b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/store/modules/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,16 @@ class API {
/** @mobx actions */

/**
* show a history data
* show a history data (-1 to disable)
*/
showHistory(data: HistoryData | null) {
this.history = data;
showHistory(index: number) {
if (index < 0 || index >= 5 || !this.historys[index]) {
this.history = null;
return;
}
// direct set reference instead of deep clone,
// for Object.is() comparsion
this.history = this.historys[index];
}
/**
* update new combat data
Expand Down
4 changes: 2 additions & 2 deletions src/views/SettingsHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function SettingsHistory() {
current={!api.history}
duration={api.data.encounter.duration}
zone={api.data.encounter.zoneName}
onClick={() => api.showHistory(null)}
onClick={() => api.showHistory(-1)}
/>
{api.historys.map((item, idx) => {
return (
Expand All @@ -79,7 +79,7 @@ function SettingsHistory() {
time={item.time}
duration={item.encounter.duration}
zone={item.encounter.zoneName}
onClick={() => api.showHistory(item)}
onClick={() => api.showHistory(idx)}
/>
);
})}
Expand Down

0 comments on commit 325fa0b

Please sign in to comment.