【发布时间】:2018-11-04 08:04:07
【问题描述】:
我一直在编写我的 React/Rediux/Firebase 应用程序(大约 1 年前开始,但在此期间我有几个月的休息时间 - 所以我可以从时间的角度查看我自己的代码)。 现在我再次检查代码,我有直觉认为它不是最先进的。
我也在使用 Firebase 来管理帐户,在这种情况下是为了创建一个新帐户
我将与创建用户和错误处理相关的所有操作链放在 Actions/index.js 中的一个功能块中。
export const signUpUser = (data) => dispatch => {
Firebase.auth().createUserAndRetrieveDataWithEmailAndPassword(data.email, data.password)
.then(response => {
const userId = Firebase.auth().currentUser()
getUserInfoRef(userId).set({
uid: userId,
isAdmin: false
})
})
.then(response => {
Firebase.auth().currentUser().updateProfile({
displayName: `${data.name} ${data.surname}`
})
})
.then(() => {
dispatch(sendEmailVerification())
})
.catch(error => {
console.log('Error during signUpUser', error)
dispatch(authError(error))
})
}
但这是一个好方法吗? 从它的身体发出动作不是某种反模式吗? 也许应该以某种方式拆分(如何?)?
它正在工作,但我对它的外观并不满意 :) 请指教。
【问题讨论】: