Support both `_actions` and `actions` for delegating

This commit is contained in:
Robin Ward 2016-11-03 11:52:30 -04:00
parent 95c8d66fe0
commit beac81d0ee
4 changed files with 27 additions and 12 deletions

View File

@ -1,6 +1,7 @@
import computed from 'ember-addons/ember-computed-decorators';
import DelegatedActions from 'discourse/mixins/delegated-actions';
export default Ember.Component.extend({
export default Ember.Component.extend(DelegatedActions, {
elementId: 'topic-footer-buttons',
// Allow us to extend it
@ -8,15 +9,7 @@ export default Ember.Component.extend({
init() {
this._super();
this._actions = this._actions || {};
(this.get('topicDelegated') || []).forEach(m => {
this._actions[m] = function() {
this.sendAction(m);
};
this.set(m, m);
});
this.delegateAll(this.get('topicDelegated'));
},
@computed('topic.details.can_invite_to')

View File

@ -0,0 +1,16 @@
export const TARGET_NAME = (Ember.VERSION[0] === "2") ? 'actions' : '_actions';
export default Ember.Mixin.create({
delegateAll(actionNames) {
actionNames = actionNames || [];
this[TARGET_NAME] = this[TARGET_NAME] || {};
actionNames.forEach(m => {
this[TARGET_NAME][m] = function() { this.sendAction(m); };
this.set(m, m);
});
}
});

View File

@ -1,6 +1,11 @@
import { WidgetClickHook, WidgetClickOutsideHook, WidgetKeyUpHook, WidgetKeyDownHook, WidgetDragHook } from 'discourse/widgets/hooks';
import { WidgetClickHook,
WidgetClickOutsideHook,
WidgetKeyUpHook,
WidgetKeyDownHook,
WidgetDragHook } from 'discourse/widgets/hooks';
import { h } from 'virtual-dom';
import DecoratorHelper from 'discourse/widgets/decorator-helper';
import { TARGET_NAME } from 'discourse/mixins/delegated-actions';
function emptyContent() { }
@ -266,7 +271,7 @@ export default class Widget {
if (target) {
// TODO: Use ember closure actions
const actions = target._actions || target.actionHooks || {};
const actions = target[TARGET_NAME] || target.actionHooks || {};
const method = actions[actionName];
if (method) {
promise = method.call(target, param);

View File

@ -25,6 +25,7 @@
//= require ./discourse/lib/formatter
//= require ./discourse/lib/eyeline
//= require ./discourse/mixins/scrolling
//= require ./discourse/mixins/scrolling
//= require ./discourse/models/model
//= require ./discourse/models/rest
//= require ./discourse/models/badge-grouping