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