Allow `modifyClass` to operate on optional classes.

This is useful if you want to modify an admin class that might not be
present for regular users.
This commit is contained in:
Robin Ward 2017-09-23 07:59:23 -04:00
parent 09ed2ed749
commit e809996c2a
1 changed files with 10 additions and 1 deletions

View File

@ -54,12 +54,21 @@ class PluginApi {
* }); * });
* ``` * ```
**/ **/
modifyClass(resolverName, changes) { modifyClass(resolverName, changes, opts) {
opts = opts || {};
if (this.container.cache[resolverName]) { if (this.container.cache[resolverName]) {
console.warn(`"${resolverName}" was already cached in the container. Changes won't be applied.`); console.warn(`"${resolverName}" was already cached in the container. Changes won't be applied.`);
} }
const klass = this.container.factoryFor(resolverName); const klass = this.container.factoryFor(resolverName);
if (!klass) {
if (!opts.ignoreMissing) {
console.warn(`"${resolverName}" was not found by modifyClass`);
}
return;
}
klass.class.reopen(changes); klass.class.reopen(changes);
return klass; return klass;
} }