Reputation: 177
I'm creating a new plugin based off the Aurelia Skeleton Plugin. But I don't know how to make it configurable. I want users to set a property (an API path specifically) when they add my plugin. So that whenever they use the plugin it's configured how they need.
Upvotes: 2
Views: 663
Reputation: 26406
configure
method:configure(frameworkConfig, callback) {
const myPluginConfiguration = new MyPluginConfiguration();
if (callback instanceof Function) {
callback(myPluginConfiguration);
}
myPluginConfiguration.apply();
The application consuming your plugin would do something like this in their main.js
...
.plugin('my-plugin', config => config.apiPath('https://api.foo.com/'))
...
And your plugin's configuration class might look something like this:
export class MyPluginConfiguration {
apiPath(path) {
// do something with path
}
apply() {
// any final configuration...
}
}
Here's an official example: https://github.com/aurelia/validation/blob/master/src/aurelia-validation.ts#L53
Upvotes: 2