class UserStore {
@observable rules = {
data:[],
isFeatching: false,
error:false,
};
@observable rooms = {
data:[],
isFeatching: false,
error:false,
};
@observable money = {
data:[],
isFeatching: false,
error:false,
};
@action
async getRules() {
try {
this.rules.isFeatching = true;
const data = await api.getRules();
this.rules.isFeatching = false;
}
}
@action
async getRooms() {
try {
this.rooms.isFeatching = true;
const data = await api.getRooms();
this.rooms.isFeatching = false;
}
}
@action
async getMoney() {
try {
this.money.isFeatching = true;
const data = await api.getMoney();
this.money.isFeatching = false;
}
}
}
Помогите мне, пожалуйста.
Условия проблемы:
1) Мне нужно получить три типа данных в одном магазине.
Задача Задача:
1) Как сделать так, чтобы «isFeatching» автоматически размещался?
Есть ли способ автоматизировать?
У меня была следующая мысль:
Создайте глобальный массив (или класс, от которого я унаследую):
const globalManagerFetching = {UserStore: {
getRules: {isFeatching:false}
getRooms: {isFeatching:false}
getMoney: {isFeatching:false}
}
Но как это сделать?
Как я могу получить название действия?
мой псевдокод:
@action
async getMoney() {
const methoneName = 'getMoney'; // how to get it automatically?
try {
globalManagerFetching[this.constructor.name][methoneName] = false;
const data = await api.getMoney();
globalManagerFetching[this.constructor.name][methoneName] = true;
}
}
мой псевдокод другой:
@action
async getMoney() {
try {
setFetching(true);//how to do this?
const data = await api.getMoney();
setFetching(false);//how to do this?
}
}
Скажите, пожалуйста.
Извините за плохой английский