gcommands icon indicating copy to clipboard operation
gcommands copied to clipboard

refactor: Plugins

Open S222em opened this issue 2 years ago • 2 comments

Please describe the changes this PR makes and why it should be merged: This PR refactors inhibitors so that they more useful in several cases. Below is an example of how to use plugins now, and some internal systems have been changed/renamed to support/use this new system. These new plugins can provide better support for typescript, and adds more use cases in general, like a database of choice.

import { container, GClient, Plugin, PluginHookType } from 'gcommands';

new Plugin({
	name: 'some-plugin',
	[PluginHookType.AfterInitialization]: (client: GClient) => {
		container.somePlugin = client.options.somePlugin;
	},
});

declare module 'gcommands' {
        // add somePlugin to the client options
	interface GClientOptions {
		somePlugin: number;
	}
        // add somePlugin to the container
	interface Container {
		somePlugin: number;
	}
}

Yes, this system is inspired by @sapphire/framework plugin system.

Status and versioning classification:

  • This PR changes the library's interface (methods or parameters added)
  • This PR includes breaking changes (methods removed or renamed, parameters moved or removed)

S222em avatar Mar 18 '22 17:03 S222em