通过一种组合方法使用react-redux-firebase查询用户特定数据(包括填充) [英] Querying user specific data (incl. population) with react-redux-firebase in one compose method
问题描述
我正在与react-native一起使用,并遇到了使用 firebaseConnect
仅加载特定于用户的数据的问题.想象一下,有大量的 todos
, users
和 doers
,并且不想引用它们的所有元素.
i'm working with react-native and have the problem to load only user specific data with firebaseConnect
. Imagine there are thousends of todos
, users
and doers
and don't want to reference all elements of them.
首先,我的实时数据库中数据结构的快捷方式:
First of all, a shortcut of my data structure in the real time database:
- 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中有一个视图/屏幕,应在其中显示所有信息.现在,我有...
I have a view/screen in RN, where all informations should be displayed. For now, i have...
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
的身份参与,并填充 doersList
中的所有 doers
(包括特定 doer中的
user
),并且仅用一种 compose
方法即可.
When i log in the application with firebase.auth.uid = michael
, i only want to reference the list of todos
, where michael
participates in as doer
and populate all doers
in doersList
(including the user
in a specific doer
), and that all in only one single compose
method.
因此,最终的redux状态应如下所示,因为 michael
只是cleanRoom的 doer
:
So the resulting redux state should look like this, because michael
is only a doer
for 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
此任务可能吗?如果是,我该怎么做?有什么结构性建议吗?
Is this task possible? If yes, how do i get this done? Any structural suggestions?
推荐答案
由另一个填充参数填充诸如 doerList
之类的列表.
Populating a list like doerList
is done by another populate parameter.
将填充数组更改为...
Changing the populate array to...
const populatesTodoCreator = [
{ child: 'createdBy', root: 'users' },
{ child: 'doerList', root: 'doers' } // populates the whole list of elements
]
为我工作.
仅查询登录用户参与的 todos
,并在 doer
对象中填充 user
(以获取预期的结果)结果)是另一个问题.
Querying only the todos
, where the logged in user is participating in and populating the user
within the doer
object (to get the expected result) is another question.
这篇关于通过一种组合方法使用react-redux-firebase查询用户特定数据(包括填充)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!