Skip to content

offirgolan/ember-evented-behaviors

Repository files navigation

Ember Evented Behaviors

Build Status npm version

Features

Installation

ember install ember-evented-behaviors

Helpful Links

Looking for help?

If it is a bug please open an issue on GitHub.

Usage

Creating a Behavior

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
  }
});

Register a Behavior

// 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' })
    ]);
  }
});

Behavior API

subscribeEvents

subscribeEvents() {
  this.subscribe('shiftClick', onEvent('click', 'shift'));
  this.subscribe('selectAll', keyDown('cmd+KeyA'));
}

subscribe

subscribe(methodNameOrCallback, eventNames, once = false)
subscribe('onClick', [ onEvent('click'), onEvent('onClick') ], true);

unsubscribe

unsubscribe(methodNameOrCallback, eventNames, once = false)
unsubscribe('onClick', [ onEvent('click'), onEvent('onClick') ], true);

register

register(object)

unregister

unregister(object)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published