Skip to content
This repository was archived by the owner on Apr 10, 2022. It is now read-only.

Proposal: Extension Structure #1

Open
Wolvan opened this issue Aug 15, 2019 · 4 comments
Open

Proposal: Extension Structure #1

Wolvan opened this issue Aug 15, 2019 · 4 comments

Comments

@Wolvan
Copy link
Member

Wolvan commented Aug 15, 2019

I propose the following structure for XKit 8 extension:

ES6 Module

BaseExtension.js

class XKitExtension {
  constructor(XKit) {
    this.api = XKit;
  }

  get __meta() {
    return {
      Name: 'Unnamed',
      Version: 'X.Y.Z',
      ShortDescription: 'Base Extension',
      Description: 'The base class for XKit Extensions',
      Authors: ['new-xkit'],
    };
  }

  get __preferences() {
    return [
      {
        Name: 'Preference 1',
        default: true,
      },
    ];
  }

  async install() {
    // The extension has been installed for the first time
  }
  async reinstall() {
    // The extension has been installed before but has now been reinstalled
  }
  async update(previousVersion, currentVersion) {
    // The extension has been updated to the latest version
  }
  async start() {
    // The extension is being loaded by the framework as part of boostrap
  }
  async stop() {
    // The extension is being unloaded
  }
  get api() {
    return {}; // Functions that are going to be called by other Extensions are set here -> Sandboxing
  }
}

XKit Extension:

class DemoExtension extends XKitExtension {
  update(prevVersion, currentVersion) {
    console.log(`You have succesfully updated DemoExtension from ${prevVersion} to ${currentVersion}`);
  }
  enable() {
    this.api.doStuffToTumblr();
  }
}

Questions to answer:

  • Are all the functions necessary? For example is there a point to having an extension know it has been installed before?
  • Are there any functions missing?
  • What are the function signatures?
  • What else should be put into the __meta block
  • How do we handle defining preferences?
@nightpool
Copy link
Member

Why have a class? When would an extension be instantiated more then once?

@Wolvan
Copy link
Member Author

Wolvan commented Aug 16, 2019

The reason I chose a class here is because it makes it easy to extend. If we were just using an object how would people best do inheriting from an object?

We do instance only once, you're right

@nightpool
Copy link
Member

nightpool commented Aug 16, 2019 via email

@Wolvan
Copy link
Member Author

Wolvan commented Aug 16, 2019

The reason I went with a class is that we can modify the base class, add new functions and have all inheriting Extensions immediately work with the new system without them having to update.
We won't have to do any checks for "Hey, does this extension actually have this function?" because it will by inheriting the base Extension. It makes writing a loading and managing mechanism for it predictable.
Also I feel like instanceof is going to come in handy.

I also realized I forgot to make __meta static, that was an oversight.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants