Files
discourse/app/assets/javascripts/discourse/components/plugin-connector.js.es6
Joffrey JAFFEUX 5cb99d08ed FIX: define actions on connector class early (#6763)
This would prevent failure with connectors templates defining actions as closures. In this case action existence is checked at compile time and not runtime.
2018-12-13 15:43:30 +01:00

31 lines
895 B
JavaScript

import { observes } from "ember-addons/ember-computed-decorators";
export default Ember.Component.extend({
init() {
this._super();
const connector = this.get("connector");
this.set("layoutName", connector.templateName);
const args = this.get("args") || {};
Object.keys(args).forEach(key => this.set(key, args[key]));
const connectorClass = this.get("connector.connectorClass");
connectorClass.setupComponent.call(this, args, this);
this.set("actions", connectorClass.actions);
},
@observes("args")
_argsChanged() {
const args = this.get("args") || {};
Object.keys(args).forEach(key => this.set(key, args[key]));
},
send(name, ...args) {
const connectorClass = this.get("connector.connectorClass");
const action = connectorClass.actions[name];
return action ? action.call(this, ...args) : this._super(name, ...args);
}
});