Upgrading to Plugins V2


#1

Plugins have been hugely improved in LipSurf v2. The new plugins allow for simpler peripheral functions and external imports. Structurally, plugins have slightly changed, so any v1 plugins need to have minor adjustments to work in LipSurf v2+.

Peripheral functions no longer need to be declared within the exported Plugin variable. They can now be ordinary top-level functions that commands call via fn, or pageFn, for example.

The excerpt below illustrates all the changes that need to be made:

Before:

import { PluginBase } from '../PluginBase';

interface IMyPlugin extends IPlugin {
    myPeriphFunction: () => void;
}

export module MyPlugin {
  export let Plugin: IPlugin & IPluginBase = Object.assign<{}, IPluginBase, IPlugin>({}, PluginBase, {
    niceName: 'My Plugin',
    myPeriphFunction: () => {
    },
    ...

After:

declare const PluginBase: IPluginBase;

function myPeriphFunction() {
}

export default <IPlugin & IPluginBase> {...PluginBase, ...{ 
  niceName: 'My Plugin',
  ...