这是我的 Mobx 商店:
import { observable } from 'mobx';
import fb from '../Firebase';
import User from '../User';
export default class Profile {
@observable profile = {};
@observable uid = null;
/**
* @return {void}
*/
constructor(user) {
this.user = user;
fb.firebase.auth().onAuthStateChanged(() => {
this.uid = user.currentUser.uid;
fb.profiles.child(this.uid).on('value', (snapshot) => {
// Doesn't matter what I will do here with this.profile...
this.profile = snapshot.val();
});
});
}
}
尝试使用观察者的配置文件可观察属性。但由于某种原因,我无法从中获得更新的状态。
如果我在“fb.profiles.child”之前更新配置文件而不是从回调中更新,那么它将起作用。
任何人都知道为什么会这样?我想可能是因为它已经安装到观察者或类似的东西......