代码之家  ›  专栏  ›  技术社区  ›  Let Me Tink About It

React Redux Firebase文档中不寻常的json语法。有效吗?

  •  1
  • Let Me Tink About It  · 技术社区  · 7 年前

    The documentation to React-Redux-Firebase provides the following sample code.

    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 }
    

    2 回复  |  直到 7 年前
        1
  •  1
  •   Let Me Tink About It    7 年前

    populates 'abc'

    { path: 'todos', populates }
    

    方法

    { path: 'todos', populates: 'abc' }
    

    然而, 可以是任何可以在对象内部使用的有效值。

    因此,在您的特定情况下,它将转换为:

    {
     path: 'todos',
     populates: [{
      child: 'owner',
      root: 'users'
     }]
    }
    

    裁判: https://ariya.io/2013/02/es6-and-object-literal-property-value-shorthand

        2
  •  1
  •   Vishal Sharma    7 年前

    { path: 'todos', populates }

    这基本上就是,

    { 
       path: 'todos',
       populates:  [
         { child: 'owner', root: 'users' }
       ]
    }
    

    注意, populates