我正在为Firebase编写一个数据库包装
react.js
如下:
function withExistingUser( uid : string , next : any ){
const bad = [".", "#", "$", "[", "]"];
const isgood = bad.map( x => (uid.indexOf(x)===-1) )
.reduce((x,y) => x && y, true);
if (isgood) {
const res = firebaseApp.database()
.ref('/users/' + uid).once('value')
.then( snap => {
if ( snap.val() !== undefined && snap.val() !== null )
next(snap.val())
})
return res;
} else {
// I need to return a `res` here
}
}
我需要返回一个
response
对象的最后一个错误消息
else
陈述,这样我就可以
then
和
catch
以后使用时
withExistingUser
,否则我会在应用程序中遇到灾难性故障。谷歌搜索不返回如何创建
反应物
我想要的响应对象。有什么想法吗?