Skip to content

Commit

Permalink
Move to mixin approach.
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanhammond committed Nov 24, 2015
1 parent 17c770b commit 21bc46d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 82 deletions.
26 changes: 2 additions & 24 deletions addon/initializers/allow-link-action.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,8 @@
import Ember from 'ember';
import LinkActionMixin from '../mixins/link-action';

export function initialize() {
Ember.LinkComponent.reopen({
_sendInvokeAction() {
this.sendAction('invokeAction');
},

init() {
this._super(...arguments);

// Map desired event name to invoke function
const eventName = this.get('eventName');

if (this.get('invokeAction')) {
this.on(eventName, this, this._sendInvokeAction);
}

this.on(eventName, this, this._invoke);
},

willDestroyElement() {
if (this.get('invokeAction')) {
this.off(this.get('eventName'), this, this._sendInvokeAction);
}
}
});
Ember.LinkComponent.reopen(LinkActionMixin);
}

export default {
Expand Down
26 changes: 26 additions & 0 deletions addon/mixins/link-action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Ember from 'ember';

export default Ember.Mixin.create({
_sendInvokeAction() {
this.sendAction('invokeAction');
},

init() {
this._super(...arguments);

// Map desired event name to invoke function
const eventName = this.get('eventName');

if (this.get('invokeAction')) {
this.on(eventName, this, this._sendInvokeAction);
}

this.on(eventName, this, this._invoke);
},

willDestroyElement() {
if (this.get('invokeAction')) {
this.off(this.get('eventName'), this, this._sendInvokeAction);
}
}
});
1 change: 1 addition & 0 deletions app/mixins/link-action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-link-action/mixins/link-action';
58 changes: 0 additions & 58 deletions tests/unit/initializers/allow-link-action-test.js

This file was deleted.

0 comments on commit 21bc46d

Please sign in to comment.