imports/vx/client/code/vxapp.js
/**
     * Conditionally set a redux property, which contains the publishing criteria for a
     * single record, to arbitrarily select the first record in a list. This is nececessary
     * to initialize the redux store the first time a route is rendered.
     *
     * @param {string} reduxPropertyName Name of redux property to initialize.
     * @param {object} setAction Redux set action.
     * @param {function} listFunction Function to return an array of records.
     */
Conditionally set a redux property, which contains the publishing criteria for a
single record, to arbitrarily select the first record in a list. This is nececessary
to initialize the redux store the first time a route is rendered.

@param {string} reduxPropertyName Name of redux property to initialize.
@param {object} setAction Redux set action.
@param {function} listFunction Function to return an array of records.
Conditionally set a redux property which contains the publishing criteria for a single record to arbitrarily select the first record in a list . This is nececessary to initialize the redux store the first time a route is rendered . @param { string } reduxPropertyName Name of redux property to initialize . @param { object } setAction Redux set action . @param { function } listFunction Function to return an array of records .
selectFirstRecord(reduxPropertyName, setAction, listFunction) {
        OLog.debug(`vxapp.js selectFirstRecord *init* reduxPropertyName=${reduxPropertyName}`)
        if (Store.getState()[reduxPropertyName]) {
            OLog.debug("vxapp.js selectFirstRecord redux already intialized " +
                `${reduxPropertyName}=${OLog.debugString(Store.getState()[reduxPropertyName])}`)
            return
        }
        OLog.debug(`vxapp.js selectFirstRecord invoking list function ${Util.functionName(listFunction)}`)
        const array = listFunction()
        if (!array || array.length === 0) {
            OLog.error(`vxapp.js selectFirstRecord ${Util.functionName(listFunction)} returned *falsy* ` +
                `unable to initialize redux variable ${reduxPropertyName}`)
            return
        }
        const publish = {}
        publish.criteria = { _id: array[0]._id }
        publish.options = {}
        OLog.debug(`vxapp.js selectFirstRecord *overriding* ${reduxPropertyName} criteria=${OLog.debugString(publish)}`)
        Store.dispatch(setAction(publish))
    }
selectFirstRecord ( reduxPropertyName , setAction , listFunction ) { OLog . debug ( ` ${ reduxPropertyName } ` ) if ( Store . getState ( ) [ reduxPropertyName ] ) { OLog . debug ( "vxapp.js selectFirstRecord redux already intialized " + ` ${ reduxPropertyName } ${ OLog . debugString ( Store . getState ( ) [ reduxPropertyName ] ) } ` ) return } OLog . debug ( ` ${ Util . functionName ( listFunction ) } ` ) const array = listFunction ( ) if ( ! array || array . length === 0 ) { OLog . error ( ` ${ Util . functionName ( listFunction ) } ` + ` ${ reduxPropertyName } ` ) return } const publish = { } publish . criteria = { _id : array [ 0 ] . _id } publish . options = { } OLog . debug ( ` ${ reduxPropertyName } ${ OLog . debugString ( publish ) } ` ) Store . dispatch ( setAction ( publish ) ) }
Conditionally set a redux property, which contains the publishing criteria for a
 single record, to arbitrarily select the first record in a list.
Conditionally set a redux property which contains the publishing criteria for a single record to arbitrarily select the first record in a list .