Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: extend Base constructor options with plugins #56

Merged
merged 2 commits into from
Jun 18, 2021

Conversation

gr2m
Copy link
Owner

@gr2m gr2m commented Jun 18, 2021

Given a plugin uses the constructor options

/**
 * @param {import('../..').Base} base
 * @param {import('../..').Base.Options} options
 */
export function withOptionsPlugin(base, options) {
  return {
    getFooOption() {
      return options.foo;
    },
  };
}

We want the plugin to be able to extend Base.Options so that when doing

import { Base } from "javascript-plugin-architecture-with-typescript-definitions";
import { withOptionsPlugin } from "plugin-with-options";

const Test = Base.plugin(withOptionsPlugin);

const test = new Test({});

The editor should suggest foo as a constructor option for new Test({})

Bonus

Extending Base.Options globally is great. But it would be even better if it was possible that the foo option only in a constructor that has the plugin loaded:

new Test({
  // should suggest `foo`
});
new Base({
  // should _not_ suggest `foo`
});

@gr2m gr2m merged commit bd9d789 into main Jun 18, 2021
@gr2m gr2m deleted the plugin-with-constructor-options-extension branch June 18, 2021 20:24
@github-actions
Copy link

🎉 This PR is included in version 3.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

None yet

1 participant