Actions

register actions with Dashboard.

With actions you can share your functions all around the Dashboard.

Use your actions inside your plugin, or other plugins.

The idea behind Actions is to give plugins the power of using other plugins functions and business logic or to share your functions with other plugins

How to register an Action?

You can register Actions from the Agent only, and only once.

You can register one or more actions with registerAction method that your Agent will get as long as you extend your Agent from the Agent-Base from Plugin-API

Action object:

{
    id: '@plugin_bundle-my-awesome-action',
    description: 'My awesome action, to handle awesome things!',
    action: () => {// My awesome action}
}

register

You can pass on Action object to registerActions or an array of Action objects

import { Plugin } from '@root'

export default class MyAgent extends Plugin.Agent {
    constructor(props) {
        super(props)

        const myActions = [
            {
                id: 'my-logger-action',
                description: 'A logger action to style logs outputs',
                action: this._logger.bind(this)
            },
            {
                id: 'my-fetch-action',
                description: 'A fetch action to handle fetch requests',
                action: this._fetch.bind(this)
            }
        ]

        this.registerActions(actions)
    }

    _logger(message) {
        console.log('=====')
        console.log(message)
        console.log('=====')
    }

    _fetch(url) {
        return new Promise((resolve, reject) => {
            this.request(url).then(resp => resp.json()).then(data => {
                resolve(data)
            }).catch(error => {
                reject(error)
            })
        })
    }
}

How to use an Action?

Last updated