Reducers

register reducers with Dashboard.

Dashboard uses redux for state management. This mean you also can register your state into the Dashboard management in order to keep a state when swapping workspaces and an unmount of your application is happening.

example

Registering a plugin with reducers.

import DashboardPlugin from 'Dashboard/plugin'

import search from 'reducers/search'
import navigations from 'reducers/navigations'

const Plugin = new DashboardPlugin('@plugin_bundle')

const registerPlugin = () => {
    const { Application } = require('@components/Application')
    
    Plugin.register({
        application: Application,

        reducers: {
    	    search,
    	    navigations,
        }
    })
}

registerPlugin()

export {
    Plugin
}

The idea behind registering reducers with Dashboard is when your Application is unmounted by switching to another workspace for example, Dashboard will hold your store state, so when your Application mounts again it can display the previous state.

By default your store will be shared with all your Dashboard components and can be accessed from the props, so if you have two Applications in the same workspace, they both will have the same store, it means any changes on the state it will effect the other, that applies to the Widget if it has been registered as well!

You can disable sharing your store so each Application will have their own store by passing sharedReducers: false with the register method.

example

Registering a plugin with un-shared reducers.

import DashboardPlugin from 'Dashboard/plugin'

import search from 'reducers/search'
import navigations from 'reducers/navigations'

const Plugin = new DashboardPlugin('@plugin_bundle')

const registerPlugin = () => {
    const { Application } = require('@/Application')
    
    Plugin.register({
        application: Application,

        reducers: {
    	    search,
    	    navigations,
        },
        
        sharedReducers: false
    })
}

registerPlugin()

export {
    Plugin
}

You can also apply your own middleware as an Array with the register method

example

Registering a plugin with un-shared reducers and with a custom middleware.

import DashboardPlugin from 'Dashboard/plugin'

import search from 'reducers/search'
import navigations from 'reducers/navigations'

import cacheMiddleware from 'middlewares/cache'

const Plugin = new DashboardPlugin('@plugin_bundle')

const registerPlugin = () => {
    const { Application } = require('@/Application')
    
    Plugin.register({
        application: Application,

        reducers: {
    	    search,
    	    navigations,
        },
        
        sharedReducers: false,

        middlewares: [
    	    cacheMiddleware
        ]
    })
}

registerPlugin()

export {
    Plugin
}

Last updated