Register - Infomaker/Dashboard-Plugin GitHub Wiki

When the Dashboard have loaded the index.js successfully it will be executed and the Dashboard.register function will be call and the plugin will register itself in the Dashboard. For this to be successful an Agent, Application or Widget must be defined in the object passed to Dashboard.register.

The only difference in how these classes is registered is that an Agent is also initialized in this stage.

What can i register?

register() method takes one arrgument type Object. In order for your plugin to work and be registered in Dashboard you need to register your plugin unique bundle, the same one in manifest.json file, and at least one of Dashboard components Application, Widget, Agent, Settings and Health

example

Registering a plugin with an Application and Settings components.

import { register } from 'Dashboard'

import Settings from '@/Settings'
import Application from '@/Application'

(() => {
    register({
    	bundle: '@plugin_bundle',
    	settings: Settings,
    	application: Application,
    })
})()

You also can register a reducers state for your plugin. In this case Dashboard will create a redux store for you and will combine all your reducers.

example

Registering a plugin with reducers.

import { register } from 'Dashboard'

import Application from '@/Application'

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

(() => {
    register({
    	bundle: '@plugin_bundle',
    	application: Application,
    	
    	reducers: {
    	    search,
    	    navigations,
    	}
    })
})()

The idea behind registering reducers with Dashboard is when your Application is unmounted by switching to anouther workspace for example, Dashboard will hold your store state, so when your Application mounts again it can back to 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 shering your store so each Application will have thier own store by passing sharedReducers: false with the register method.

example

Registering a plugin with un-shared reducers.

import { register } from 'Dashboard'

import Application from '@/Application'

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

import cacheMiddleware from 'middlewares/cache'

(() => {
    register({
    	bundle: '@plugin_bundle',
    	application: Application,
    	
    	reducers: {
    	    search,
    	    navigations,
    	},
    	sharedReducers: false
    })
})()

You can also apply your own middlewares as an Array with the register mwthod

example

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

import { register } from 'Dashboard'

import Application from '@/Application'

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

(() => {
    register({
    	bundle: '@plugin_bundle',
    	application: Application,
    	
    	reducers: {
    	    search,
    	    navigations,
    	},
    	sharedReducers: false,
    	middlewares: [
    	    cacheMiddleware
    	]
    })
})()