imports/vx/client/code/vxapp.js
/**
     * Set up global subscriptions if necessary.
     *
     * @param {object} newSubscriptionParameters Subscription parameters object.
     * @param {function} Mandatory callback.
     */
Set up global subscriptions if necessary.
@param {object} newSubscriptionParameters Subscription parameters object.
@param {function} Mandatory callback.
Set up global subscriptions if necessary . @param { object } newSubscriptionParameters Subscription parameters object . @param { function } Mandatory callback .
globalSubscriptions(newSubscriptionParameters, callback) {
        OLog.debug("vxapp.js globalSubscriptions *fire*")
        const oldSubscriptionParameters = Store.getState().subscriptionParameters
        const oldPublishingModeClient = Store.getState().publishingModeClient
        const oldPublishingModeServer = Store.getState().publishingModeServer
        const newPublishingModeClient = VXApp.getPublishingMode("client", newSubscriptionParameters)
        const newPublishingModeServer = VXApp.getPublishingMode("server", newSubscriptionParameters)
        const oldSubscriptionParametersString = JSON.stringify(oldSubscriptionParameters)
        const newSubscriptionParametersString = JSON.stringify(newSubscriptionParameters)
        const isEmpty = Config.find().count() === 0
        const isSameSubscriptionParameters = newSubscriptionParametersString === oldSubscriptionParametersString
        const isSamePublishingModeClient = newPublishingModeClient === oldPublishingModeClient
        const isSamePublishingModeServer = newPublishingModeServer === oldPublishingModeServer
        if (!isEmpty && isSameSubscriptionParameters && isSamePublishingModeClient && isSamePublishingModeServer) {
            OLog.debug(`vxapp.js globalSubscriptions ${newSubscriptionParameters.email} all parameters *match* no action will be taken`)
            VXApp.doContextMakerBeforeRender()
            callback(null, { success: true })
            UX.setLoading(false)
            return
        }
        if (!isSameSubscriptionParameters) {
            OLog.debug(`vxapp.js globalSubscriptions ${newSubscriptionParameters.email} subscription parameters *changed* and will be updated`)
            Store.dispatch(setSubscriptionParameters(newSubscriptionParameters))
        }
        const doClient = isEmpty || !isSameSubscriptionParameters || !isSamePublishingModeClient
        const doServer = isEmpty || !isSameSubscriptionParameters || !isSamePublishingModeServer
        OLog.debug(`vxapp.js globalSubscriptions ${newSubscriptionParameters.email} doClient=${doClient} doServer=${doServer} ` +
            `newPublishingModeClient=${newPublishingModeClient} newPublishingModeServer=${newPublishingModeServer}`)
        if (doClient) {
            Store.dispatch(setPublishingModeClient(newPublishingModeClient))
        }
        if (doServer) {
            Store.dispatch(setPublishingModeServer(newPublishingModeServer))
        }
        let handles = VXApp.changeGlobalSubscriptions(doClient, doServer, newSubscriptionParameters)
        if (VXApp.changeAppGlobalSubscriptions) {
            handles = handles.concat(VXApp.changeAppGlobalSubscriptions(doClient, doServer, newSubscriptionParameters))
        }
        OLog.warn("vxapp.js globalSubscriptions have been computed *wait* for publication")
        UX.setLoading(true)
        UX.waitSubscriptions(handles, (error, result) => {
            if (VXApp.onAppChangeSubscriptionsReady) {
                VXApp.onAppChangeSubscriptionsReady()
            }
            VXApp.addAllFunctions()
            VXApp.doContextMakerBeforeRender()
            OLog.debug(`vxapp.js globalSubscriptions ready domain count=${Domains.find().count()}`)
            callback(error, result)
            UX.setLoading(false)
            return
        })
        return
    }
globalSubscriptions ( newSubscriptionParameters , callback ) { OLog . debug ( "vxapp.js globalSubscriptions *fire*" ) const oldSubscriptionParameters = Store . getState ( ) . subscriptionParameters const oldPublishingModeClient = Store . getState ( ) . publishingModeClient const oldPublishingModeServer = Store . getState ( ) . publishingModeServer const newPublishingModeClient = VXApp . getPublishingMode ( "client" , newSubscriptionParameters ) const newPublishingModeServer = VXApp . getPublishingMode ( "server" , newSubscriptionParameters ) const oldSubscriptionParametersString = JSON . stringify ( oldSubscriptionParameters ) const newSubscriptionParametersString = JSON . stringify ( newSubscriptionParameters ) const isEmpty = Config . find ( ) . count ( ) === 0 const isSameSubscriptionParameters = newSubscriptionParametersString === oldSubscriptionParametersString const isSamePublishingModeClient = newPublishingModeClient === oldPublishingModeClient const isSamePublishingModeServer = newPublishingModeServer === oldPublishingModeServer if ( ! isEmpty && isSameSubscriptionParameters && isSamePublishingModeClient && isSamePublishingModeServer ) { OLog . debug ( ` ${ newSubscriptionParameters . email } ` ) VXApp . doContextMakerBeforeRender ( ) callback ( null , { success : true } ) UX . setLoading ( false ) return } if ( ! isSameSubscriptionParameters ) { OLog . debug ( ` ${ newSubscriptionParameters . email } ` ) Store . dispatch ( setSubscriptionParameters ( newSubscriptionParameters ) ) } const doClient = isEmpty || ! isSameSubscriptionParameters || ! isSamePublishingModeClient const doServer = isEmpty || ! isSameSubscriptionParameters || ! isSamePublishingModeServer OLog . debug ( ` ${ newSubscriptionParameters . email } ${ doClient } ${ doServer } ` + ` ${ newPublishingModeClient } ${ newPublishingModeServer } ` ) if ( doClient ) { Store . dispatch ( setPublishingModeClient ( newPublishingModeClient ) ) } if ( doServer ) { Store . dispatch ( setPublishingModeServer ( newPublishingModeServer ) ) } let handles = VXApp . changeGlobalSubscriptions ( doClient , doServer , newSubscriptionParameters ) if ( VXApp . changeAppGlobalSubscriptions ) { handles = handles . concat ( VXApp . changeAppGlobalSubscriptions ( doClient , doServer , newSubscriptionParameters ) ) } OLog . warn ( "vxapp.js globalSubscriptions have been computed *wait* for publication" ) UX . setLoading ( true ) UX . waitSubscriptions ( handles , ( error , result ) => { if ( VXApp . onAppChangeSubscriptionsReady ) { VXApp . onAppChangeSubscriptionsReady ( ) } VXApp . addAllFunctions ( ) VXApp . doContextMakerBeforeRender ( ) OLog . debug ( ` ${ Domains . find ( ) . count ( ) } ` ) callback ( error , result ) UX . setLoading ( false ) return } ) return }
Set up global subscriptions if necessary.
Set up global subscriptions if necessary .
// Initialize redux store prior to rendering to comply with React best practices: