mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-23 19:45:15 +00:00
Reorder botStoreWrapper
This commit is contained in:
parent
a2d8b68abb
commit
8579499418
|
@ -1,22 +1,48 @@
|
||||||
import { BotStoreActions, BotStoreGetters, createBotSubStore } from './ftbot';
|
import { BotStoreActions, BotStoreGetters, createBotSubStore } from './ftbot';
|
||||||
|
|
||||||
|
interface FTMultiBotState {
|
||||||
|
selectedBot: string;
|
||||||
|
availableBots: string[];
|
||||||
|
}
|
||||||
|
|
||||||
export default function createBotStore() {
|
export default function createBotStore() {
|
||||||
const state = {
|
const state: FTMultiBotState = {
|
||||||
selectedBot: 'ftbot.0',
|
selectedBot: 'ftbot.0',
|
||||||
|
availableBots: ['ftbot.0'],
|
||||||
};
|
};
|
||||||
const actions = {
|
|
||||||
// Actions automatically filled below
|
// All getters working on all bots should be prefixed with all.
|
||||||
addBot(context, botName: string) {
|
const getters = {
|
||||||
//
|
selectedBot(state: FTMultiBotState) {
|
||||||
|
return state.selectedBot;
|
||||||
|
},
|
||||||
|
allAvailableBots(state: FTMultiBotState) {
|
||||||
|
return state.availableBots;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const getters = {};
|
|
||||||
// Autocreate getters
|
// Autocreate getters
|
||||||
Object.keys(BotStoreGetters).forEach((e) => {
|
Object.keys(BotStoreGetters).forEach((e) => {
|
||||||
getters[e] = (state, getters) => {
|
getters[e] = (state, getters) => {
|
||||||
return getters[`${state.selectedBot}/${e}`];
|
return getters[`${state.selectedBot}/${e}`];
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const mutations = {
|
||||||
|
addBot(state: FTMultiBotState, botName: string) {
|
||||||
|
state.availableBots = [...state.availableBots, botName];
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const actions = {
|
||||||
|
// Actions automatically filled below
|
||||||
|
addBot({ getters, commit }, botName: string) {
|
||||||
|
if (getters.allAvailableBots.includes(botName)) {
|
||||||
|
// throw 'Bot already present';
|
||||||
|
// TODO: handle error!
|
||||||
|
}
|
||||||
|
commit('addBot', botName);
|
||||||
|
},
|
||||||
|
};
|
||||||
// Autocreate Actions
|
// Autocreate Actions
|
||||||
Object.keys(BotStoreActions).forEach((e) => {
|
Object.keys(BotStoreActions).forEach((e) => {
|
||||||
actions[e] = ({ state, dispatch }, ...args) => {
|
actions[e] = ({ state, dispatch }, ...args) => {
|
||||||
|
@ -30,6 +56,8 @@ export default function createBotStore() {
|
||||||
'ftbot.0': createBotSubStore(),
|
'ftbot.0': createBotSubStore(),
|
||||||
},
|
},
|
||||||
state,
|
state,
|
||||||
|
mutations,
|
||||||
|
|
||||||
getters,
|
getters,
|
||||||
actions,
|
actions,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user