mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Allow widgets to call _super()
when reopened
This commit is contained in:
parent
a5afc08363
commit
d955af5960
@ -133,7 +133,21 @@ export function reopenWidget(name, opts) {
|
||||
opts.html = opts.template;
|
||||
}
|
||||
|
||||
Object.keys(opts).forEach(k => existing.prototype[k] = opts[k]);
|
||||
Object.keys(opts).forEach(k => {
|
||||
let old = existing.prototype[k];
|
||||
|
||||
if (old) {
|
||||
// Add support for `this._super()` to reopened widgets if the prototype exists in the
|
||||
// base object
|
||||
existing.prototype[k] = function(...args) {
|
||||
let ctx = Object.create(this);
|
||||
ctx._super = (...superArgs) => old.apply(this, superArgs);
|
||||
return opts[k].apply(ctx, args);
|
||||
};
|
||||
} else {
|
||||
existing.prototype[k] = opts[k];
|
||||
}
|
||||
});
|
||||
return existing;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user