Skip to content

Commit

Permalink
chore: refactor getters code in example counter-hot (#1801)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
7006 authored Aug 4, 2020
1 parent 3909af0 commit 4b038d7
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions examples/counter-hot/store/getters.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
export const count = state => state.count

const limit = 5

export const recentHistory = state => {
const end = state.history.length
const begin = end - limit < 0 ? 0 : end - limit
return state.history
.slice(begin, end)
.slice(-5)
.join(', ')
}

0 comments on commit 4b038d7

Please sign in to comment.