Mercurial > gemma
changeset 2502:e13daf439068 critical-bottlenecks
client: fixed Unexpected side effect in computed property
Sort mutates the array and since this array lives in the store, this would be considered a bad practice
including said side effects. Slice clones the array and we need to slice the array anyway. So simply
switching slice and sort solved the problem.
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Mon, 04 Mar 2019 16:20:57 +0100 |
parents | 9d9c6425db82 |
children | 51dbcbf11c5f |
files | client/src/components/usermanagement/Usermanagement.vue |
diffstat | 1 files changed, 7 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/client/src/components/usermanagement/Usermanagement.vue Mon Mar 04 16:01:20 2019 +0100 +++ b/client/src/components/usermanagement/Usermanagement.vue Mon Mar 04 16:20:57 2019 +0100 @@ -171,19 +171,13 @@ ...mapState("application", ["showSidebar"]), sortedUsers() { const start = (this.currentPage - 1) * this.pageSize; - return this.users - .sort((a, b) => { - if ( - a[this.sortColumn].toLowerCase() < b[this.sortColumn].toLowerCase() - ) - return this.sortDirection === "ASC" ? -1 : 1; - if ( - a[this.sortColumn].toLowerCase() > b[this.sortColumn].toLowerCase() - ) - return this.sortDirection === "ASC" ? 1 : -1; - return 0; - }) - .slice(start, start + this.pageSize); + return this.users.slice(start, start + this.pageSize).sort((a, b) => { + if (a[this.sortColumn].toLowerCase() < b[this.sortColumn].toLowerCase()) + return this.sortDirection === "ASC" ? -1 : 1; + if (a[this.sortColumn].toLowerCase() > b[this.sortColumn].toLowerCase()) + return this.sortDirection === "ASC" ? 1 : -1; + return 0; + }); }, pages() { return Math.ceil(this.users.length / this.pageSize);