Работа над HistoryPage

This commit is contained in:
Book Pauk
2019-01-26 01:47:11 +07:00
parent bcc5b27d1e
commit 641409902e
7 changed files with 145 additions and 18 deletions

View File

@@ -25,6 +25,29 @@ const getters = {
// actions
const actions = {};
function delBook(state, value) {
Vue.delete(state.openedBook, value.key);
}
function cleanBooks(state) {
if (Object.keys(state.openedBook).length > 100) {
let min = Date.now();
let found = null;
for (let bookKey in state.openedBook) {
const book = state.openedBook[bookKey];
if (book.touchTime < min) {
min = book.touchTime;
found = book;
}
}
if (found) {
delBook(found);
cleanBooks(state);
}
}
}
// mutations
const mutations = {
setToolBarActive(state, value) {
@@ -32,9 +55,10 @@ const mutations = {
},
setOpenedBook(state, value) {
Vue.set(state.openedBook, value.key, Object.assign({}, value, {touchTime: Date.now()}));
cleanBooks(state);
},
delOpenedBook(state, value) {
Vue.delete(state.openedBook, value.key);
delBook(state, value);
}
};