我正在使用 react-native 并且有问题仅加载用户特定的数据firebaseConnect
。想象一下,有成千上万个todos
,users
并且doers
不想引用它们的所有元素。
首先,我在实时数据库中的数据结构的一个快捷方式:
- todos
|- cleanRoom
| |- createdBy: alica
| |- title: "Clean the room up"
| |- doerList
| |- roomCleanerMichael
| |- roomCleanerAlica
|- playBall
|- createdBy: michael
|- title: "Play the ball"
|- doerList
|- ballPlayerAlica
- users
|- michael
| |- name: Michael
| |- age: 22
|- alica
|- name: Alica
|- age: 27
- doers
|- roomCleanerMichael
| |- user: michael
| |- status: done
|- roomCleanerAlica
| |- user: alica
| |- status: done
|- ballPlayerAlica
|- user: alica
|- status: done
我在 RN 中有一个视图/屏幕,应该显示所有信息。目前,我有...
const populatesTodoCreator = [{child: 'createdBy', root: 'users'}]
const mapStateToProps = (state, props) => {
return {
todos: populate(state.firebase, 'todos', populatesTodoCreator),
uid: state.firebase.auth.uid
}
}
export default compose(
firebaseConnect((props, store) => {
return [
{path: 'todos', populatesTodoCreator},
]
}
),
connect(mapStateToProps, mapDispatchToProps)
)(TodoOverviewScreen)
当我使用 登录应用程序时firebase.auth.uid = michael
,我只想引用列表todos
,其中michael
参与doer
并全部填充(包括特定的doers
),并且只在一个方法中。doersList
user
doer
compose
所以最终的 redux 状态应该是这样的,因为michael
它只是一个doer
用于 cleanRoom 的:
- todos
|- cleanRoom
|- createdBy
| |- name: Alica
| |- age: 27
|- title: "Clean the room up"
|- doerList
|- roomCleanerMichael
| |- user
| | |- name: Michael
| | |- age: 22
| |- status: done
|- roomCleanerAlica
|- user
| |- name: Alica
| |- age: 27
|- status: done
这个任务可以吗?如果是,我该如何完成?有什么结构建议吗?