mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-27 13:35:17 +00:00
Keep state around
This commit is contained in:
parent
f30f968a2f
commit
a253377124
|
@ -15,9 +15,8 @@ const AUTO_REFRESH = 'ft_auto_refresh';
|
||||||
Vue.use(Vuex);
|
Vue.use(Vuex);
|
||||||
const initCurrentTheme = getCurrentTheme();
|
const initCurrentTheme = getCurrentTheme();
|
||||||
|
|
||||||
export default new Vuex.Store({
|
const store = new Vuex.Store({
|
||||||
modules: {
|
modules: {
|
||||||
ftbot: createBotStore(),
|
|
||||||
alerts: alertsModule,
|
alerts: alertsModule,
|
||||||
layout: layoutModule,
|
layout: layoutModule,
|
||||||
uiSettings: settingsModule,
|
uiSettings: settingsModule,
|
||||||
|
@ -152,3 +151,7 @@ export default new Vuex.Store({
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
store.registerModule('ftbot', createBotStore(store));
|
||||||
|
store.dispatch('ftbot/addBot', 'ftbot.0');
|
||||||
|
export default store;
|
||||||
|
|
|
@ -5,18 +5,21 @@ interface FTMultiBotState {
|
||||||
availableBots: string[];
|
availableBots: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function createBotStore() {
|
export default function createBotStore(store) {
|
||||||
const state: FTMultiBotState = {
|
const state: FTMultiBotState = {
|
||||||
selectedBot: 'ftbot.0',
|
selectedBot: 'ftbot.0',
|
||||||
availableBots: ['ftbot.0'],
|
availableBots: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
// All getters working on all bots should be prefixed with all.
|
// All getters working on all bots should be prefixed with all.
|
||||||
const getters = {
|
const getters = {
|
||||||
selectedBot(state: FTMultiBotState) {
|
hasBots(state: FTMultiBotState): boolean {
|
||||||
|
return state.availableBots.length > 0;
|
||||||
|
},
|
||||||
|
selectedBot(state: FTMultiBotState): string {
|
||||||
return state.selectedBot;
|
return state.selectedBot;
|
||||||
},
|
},
|
||||||
allAvailableBots(state: FTMultiBotState) {
|
allAvailableBots(state: FTMultiBotState): string[] {
|
||||||
return state.availableBots;
|
return state.availableBots;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -35,12 +38,14 @@ export default function createBotStore() {
|
||||||
|
|
||||||
const actions = {
|
const actions = {
|
||||||
// Actions automatically filled below
|
// Actions automatically filled below
|
||||||
addBot({ getters, commit }, botName: string) {
|
addBot({ getters, commit }, botId: string) {
|
||||||
if (getters.allAvailableBots.includes(botName)) {
|
if (getters.allAvailableBots.includes(botId)) {
|
||||||
// throw 'Bot already present';
|
// throw 'Bot already present';
|
||||||
// TODO: handle error!
|
// TODO: handle error!
|
||||||
}
|
}
|
||||||
commit('addBot', botName);
|
console.log('add bot', botId);
|
||||||
|
store.registerModule(`ftbot/${botId}`, createBotSubStore(botId));
|
||||||
|
commit('addBot', botId);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
// Autocreate Actions
|
// Autocreate Actions
|
||||||
|
@ -52,9 +57,9 @@ export default function createBotStore() {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
namespaced: true,
|
namespaced: true,
|
||||||
modules: {
|
// modules: {
|
||||||
'ftbot.0': createBotSubStore('ftbot.0'),
|
// 'ftbot.0': createBotSubStore('ftbot.0'),
|
||||||
},
|
// },
|
||||||
state,
|
state,
|
||||||
mutations,
|
mutations,
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user