В RootStore определены различные сторы:
export class RootStore {
authStore: AuthStore;
profileStore: ProfileStore;
mainStore: MainStore;
pushStore: PushStore;
BLEStore: BLEStore;
constructor() {
this.authStore = new AuthStore();
this.profileStore = new ProfileStore();
this.mainStore = new MainStore();
this.pushStore = new PushStore();
this.BLEStore = new BLEStore();
}
}
export const rootStore = new RootStore();
export const storesContext = React.createContext(rootStore);
Фрагмент AuthStore:
export class AuthStore {
signInIsLoading: boolean = false;
accessToken: string | null = null;
private authService: AuthService;
private tokenService: TokenService;
constructor() {
makeAutoObservable(this);
this.authService = new AuthService();
this.tokenService = new TokenService();
}
signIn = (email: string, password: string) => {
this.setSignInLoading(true);
const postData = SignInDto.populate({email, password}) as SignInDto;
this.authService
.signIn(postData)
.then(async response => {
if (!response.token) {
// @ts-ignore
Notification.showError(
'Неправильный адрес электронной почты или пароль' || '',
);
} else {
this.tokenService.saveToken(response.token || '');
this.setToken(response.token);
await profileStore.getObservables(); <- как здесь вызвать экшн из profileStore?
Navigation.replace(Screens.TAB_STACK);
}
})
.catch((err: any) => {
Alert.alert('Ошибка сервера', err.toString());
})
.finally(() => {
this.setSignInLoading(false);
});
};
private setSignInLoading = (value: boolean) => {
this.signInIsLoading = value;
};
private setToken = (value: string | null) => {
this.accessToken = value;
};
}
Как в AuthStore вызвать экшн из ProfileStore?