mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-23 11:35:14 +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);
|
||||
const initCurrentTheme = getCurrentTheme();
|
||||
|
||||
export default new Vuex.Store({
|
||||
const store = new Vuex.Store({
|
||||
modules: {
|
||||
ftbot: createBotStore(),
|
||||
alerts: alertsModule,
|
||||
layout: layoutModule,
|
||||
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[];
|
||||
}
|
||||
|
||||
export default function createBotStore() {
|
||||
export default function createBotStore(store) {
|
||||
const state: FTMultiBotState = {
|
||||
selectedBot: 'ftbot.0',
|
||||
availableBots: ['ftbot.0'],
|
||||
availableBots: [],
|
||||
};
|
||||
|
||||
// All getters working on all bots should be prefixed with all.
|
||||
const getters = {
|
||||
selectedBot(state: FTMultiBotState) {
|
||||
hasBots(state: FTMultiBotState): boolean {
|
||||
return state.availableBots.length > 0;
|
||||
},
|
||||
selectedBot(state: FTMultiBotState): string {
|
||||
return state.selectedBot;
|
||||
},
|
||||
allAvailableBots(state: FTMultiBotState) {
|
||||
allAvailableBots(state: FTMultiBotState): string[] {
|
||||
return state.availableBots;
|
||||
},
|
||||
};
|
||||
|
@ -35,12 +38,14 @@ export default function createBotStore() {
|
|||
|
||||
const actions = {
|
||||
// Actions automatically filled below
|
||||
addBot({ getters, commit }, botName: string) {
|
||||
if (getters.allAvailableBots.includes(botName)) {
|
||||
addBot({ getters, commit }, botId: string) {
|
||||
if (getters.allAvailableBots.includes(botId)) {
|
||||
// throw 'Bot already present';
|
||||
// TODO: handle error!
|
||||
}
|
||||
commit('addBot', botName);
|
||||
console.log('add bot', botId);
|
||||
store.registerModule(`ftbot/${botId}`, createBotSubStore(botId));
|
||||
commit('addBot', botId);
|
||||
},
|
||||
};
|
||||
// Autocreate Actions
|
||||
|
@ -52,9 +57,9 @@ export default function createBotStore() {
|
|||
|
||||
return {
|
||||
namespaced: true,
|
||||
modules: {
|
||||
'ftbot.0': createBotSubStore('ftbot.0'),
|
||||
},
|
||||
// modules: {
|
||||
// 'ftbot.0': createBotSubStore('ftbot.0'),
|
||||
// },
|
||||
state,
|
||||
mutations,
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user