Skip to content

Commit 4b038d7

Browse files
authored
chore: refactor getters code in example counter-hot (#1801)
Rewrite `recentHistory` getter using negative index for`start` argument of `Array.prototype.slice`. Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
1 parent 3909af0 commit 4b038d7

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

examples/counter-hot/store/getters.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
export const count = state => state.count
22

3-
const limit = 5
4-
53
export const recentHistory = state => {
6-
const end = state.history.length
7-
const begin = end - limit < 0 ? 0 : end - limit
84
return state.history
9-
.slice(begin, end)
5+
.slice(-5)
106
.join(', ')
117
}

0 commit comments

Comments
 (0)