ember install ember-evented-behaviors
If it is a bug please open an issue on GitHub.
ember generate behavior my-behavior
// behaviors/my-behavior.js
import Ember from 'ember';
import Behavior, { onEvent } from 'ember-evented-behaviors';
import { keyDown } from 'ember-keyboard';
export default Behavior.extend({
subscribeEvents() {
this.subscribe('shiftClick', onEvent('click', 'shift'));
this.subscribe(this.selectAll, keyDown('cmd+KeyA'));
},
shiftClick(/* context, event */) {
// Do something on shift + click
},
selectAll(/* context, event */) {
// Do something on cmd + A
}
});
// components/my-component.js
import Ember from 'ember';
import { EKMixin } from 'ember-keyboard';
import { EBMixin } from 'ember-evented-behaviors';
export default Ember.Component.extend(EKMixin, EBMixin, {
behaviors: Ember.inject.service(),
init() {
this._super(...arguments);
let behaviors = this.get('behaviors');
this.registerBehaviors([
behaviors.createBehavior('my-behavior', { foo: 'bar' })
]);
}
});
subscribeEvents() {
this.subscribe('shiftClick', onEvent('click', 'shift'));
this.subscribe('selectAll', keyDown('cmd+KeyA'));
}
subscribe(methodNameOrCallback, eventNames, once = false)
subscribe('onClick', [ onEvent('click'), onEvent('onClick') ], true);
unsubscribe(methodNameOrCallback, eventNames, once = false)
unsubscribe('onClick', [ onEvent('click'), onEvent('onClick') ], true);
register(object)
unregister(object)