Перенес управление и хранение recentBooks из vuex в bookManager
This commit is contained in:
@@ -168,64 +168,20 @@ for (const font of webFonts)
|
||||
// initial state
|
||||
const state = {
|
||||
toolBarActive: true,
|
||||
openedBook: {},
|
||||
settings: Object.assign({}, settingDefaults),
|
||||
};
|
||||
|
||||
// getters
|
||||
const getters = {
|
||||
lastOpenedBook: (state) => {
|
||||
let max = 0;
|
||||
let result = null;
|
||||
for (let bookKey in state.openedBook) {
|
||||
const book = state.openedBook[bookKey];
|
||||
if (book.touchTime > max) {
|
||||
max = book.touchTime;
|
||||
result = book;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
},
|
||||
};
|
||||
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(state, found);
|
||||
cleanBooks(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// mutations
|
||||
const mutations = {
|
||||
setToolBarActive(state, value) {
|
||||
state.toolBarActive = value;
|
||||
},
|
||||
setOpenedBook(state, value) {
|
||||
Vue.set(state.openedBook, value.key, Object.assign({}, value, {touchTime: Date.now()}));
|
||||
cleanBooks(state);
|
||||
},
|
||||
delOpenedBook(state, value) {
|
||||
delBook(state, value);
|
||||
},
|
||||
setSettings(state, value) {
|
||||
state.settings = Object.assign({}, state.settings, value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user