From ed0b0237674fac2f12d589da3ef8bc516aa2a857 Mon Sep 17 00:00:00 2001 From: monkeycf <41945134+monkeycf@users.noreply.github.com> Date: Tue, 8 Oct 2019 18:15:22 +0800 Subject: [PATCH] perf[tagsView]: pref DEL_CACHED_VIEW and DEL_OTHERS_CACHED_VIEWS function (#2626) --- src/store/modules/tagsView.js | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/store/modules/tagsView.js b/src/store/modules/tagsView.js index 3e2c1703..f94546ce 100644 --- a/src/store/modules/tagsView.js +++ b/src/store/modules/tagsView.js @@ -28,13 +28,8 @@ const mutations = { } }, DEL_CACHED_VIEW: (state, view) => { - for (const i of state.cachedViews) { - if (i === view.name) { - const index = state.cachedViews.indexOf(i) - state.cachedViews.splice(index, 1) - break - } - } + const index = state.cachedViews.indexOf(view.name) + index > -1 && state.cachedViews.splice(index, 1) }, DEL_OTHERS_VISITED_VIEWS: (state, view) => { @@ -43,13 +38,8 @@ const mutations = { }) }, DEL_OTHERS_CACHED_VIEWS: (state, view) => { - for (const i of state.cachedViews) { - if (i === view.name) { - const index = state.cachedViews.indexOf(i) - state.cachedViews = state.cachedViews.slice(index, index + 1) - break - } - } + const index = state.cachedViews.indexOf(view.name) + index > -1 && (state.cachedViews = state.cachedViews.slice(index, index + 1)) }, DEL_ALL_VISITED_VIEWS: state => {