Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase Can';t在mobx存储中重写可观察变量_Firebase_React Native_Firebase Realtime Database_Mobx_Mobx React - Fatal编程技术网

Firebase Can';t在mobx存储中重写可观察变量

Firebase Can';t在mobx存储中重写可观察变量,firebase,react-native,firebase-realtime-database,mobx,mobx-react,Firebase,React Native,Firebase Realtime Database,Mobx,Mobx React,这是我的Mobx商店: 从'mobx'导入{observable}; 从“../Firebase”导入fb; 从“../User”导入用户; 导出默认类配置文件{ @可观测剖面={}; @可观察uid=null; /** *@return{void} */ 构造函数(用户){ this.user=用户; fb.firebase.auth().onAuthStateChanged(()=>{ this.uid=user.currentUser.uid; fb.profiles.child(thi

这是我的Mobx商店:

从'mobx'导入{observable};
从“../Firebase”导入fb;
从“../User”导入用户;
导出默认类配置文件{
@可观测剖面={};
@可观察uid=null;
/**
*@return{void}
*/
构造函数(用户){
this.user=用户;
fb.firebase.auth().onAuthStateChanged(()=>{
this.uid=user.currentUser.uid;
fb.profiles.child(this.uid).on('value',(快照)=>{
//不管我用这个做什么。个人资料。。。
this.profile=snapshot.val();
});
});
}

}
为了正确更新对象,您应该使用
可观察的
()和
对象。分配
来定义
配置文件

以下是几个(未经测试的)示例:

@observable profile = observable({});
.
.
.
this.profile = Object.assign({}, this.profile, snapshot.val());
如果
Object.assign
未触发更新,则需要使用
extendObservable()
():

另一种选择是对更复杂的结构使用
observable.map
():

@observable profile = observable.map({ profileData: {} });
.
.
.
const currentProfile = this.profile.get('profileData'); 
this.profile.set('profileData', Object.assign({}, currentProfile, snapshot.val()));

所以用问题解决我的问题是不可能的,最重要的部分是缺失


组件中有一个组件willmount。删除后,它解决了我的问题。

仍然不走运。如果我使用我从组件调用的简单方法将概要文件从存储区打印到控制台,那么概要文件日期将是控制台中的更新数据,但组件中的对象为空。您有过这样的经历吗?
@observable profile = observable.map({ profileData: {} });
.
.
.
const currentProfile = this.profile.get('profileData'); 
this.profile.set('profileData', Object.assign({}, currentProfile, snapshot.val()));