React-Redux-Firebase 的文档提供了以下示例代码。
import { compose } from 'redux'
import { connect } from 'react-redux'
import { firebaseConnect, populate } from 'react-redux-firebase'
const populates = [
{ child: 'owner', root: 'users' } // replace owner with user object
]
const enhance = compose(
firebaseConnect([
// passing populates parameter also creates all necessary child queries
{ path: 'todos', populates }
]),
connect(({ firebase }) => ({
// populate original from data within separate paths redux
todos: populate(firebase, 'todos', populates),
// firebase.ordered.todos or firebase.data.todos for unpopulated todos
}))
)
export default enhance(SomeComponent)
我特别担心这样一行:
{ path: 'todos', populates }
我以前从未见过这种语法。这是一个错误吗?或者它是有效的语法?如果它是有效的,请解释它的含义和它是如何工作的。