Agent

The Agent class is NOT a React Component.

Therefore none of the Component Lifecycle functions is available.

What is Agent?

The Agent is a js class, think about it like the brain of your plugin, the main component to communicate and do requests and talk to the outer world.

Agent can communicate with other components in your plugin or other plugin's Agent or component with the "plugin events dispatcher"

The plugin Agent will be initiated and initialized once the plugin register it self.

Agent will always be up and running as long as your plugin is installed and active in Dashboard.

Agent will only be turned "off" when the plugin is uninstalled or deactivated.

Once the plugin is deactivated or Dashboard window closed, Dashboard will try to call the close() function if there is one provided in the Agent.

What does the Agent look like?

You can build your Agent component by extending the Agent base from Plugin-API

import { Plugin } from '@root'

class MyAgent extends Plugin.Agent {
    constructor(props) {
        super(props)
        
        this.config = props.config
        
        this.doMagic()
    }

    doMagic() {
        // i can do magic with this.config if you want to 🧙🏿‍♂️
    }
}

export {
    MyAgent
}

Dashboard will pass custom props to your Agent including the config of your plugin to be used inside your Agent

How to register an Agent?

In your main index.js file where you register your plugin, import your Agent and pass it down with the register() method from Plugin-API

import DashboardPlugin from 'Dashboard/plugin'

const Plugin = new DashboardPlugin('@plugin_bundle')

const registerPlugin = () => {
    const { MyAgent } = require('@components/Agent')
    
    Plugin.register({
        agent: MyAgent
    })
}

registerPlugin()

export {
    Plugin
}

close()

Function that is called before agent is unregistered.

close() {
    // This is where you should for example close connections or clear intervals.
}

Last updated