Skip to content

tzellman/ember-events-modifier

Repository files navigation

ember-events-modifier

NPM Build Status Ember Observer Score Ember Version Download count Code Climate Test Coverage

Installation

ember install ember-events-modifier

Demo

Demo

Usage

The addon provides an events service which can be used to facilitate events throughout your application. You can use the service directly, without using the modifiers, described below.

import Controller from "@ember/controller";
import { action } from "@ember/object";
import { inject as service } from "@ember/service";

export default class MyController extends Controller {
    @service events;

    @action clickedBook(book) {
        this.events.trigger(`book:active:${book.id}`, book);
    }
}

on-event

The on-event modifier allows you to register a handler for specific events.

Your action handler will be passed arguments that are provided when the action is triggered.

Note that the handler is automatically registered and removed on insertion/removal, respectively.

<div {{on-event "blog-updated" this.reloadBlog}}>
    ...
</div>

You can also handle multiple events with one declaration:

<div {{on-event (array "blog-updated" "blog-created") this.reloadBlog}}>
    ...
</div>

trigger-event

The trigger-event modifier allows you to trigger an event when the element is inserted.

{{#if this.showDetails}}
    <div {{trigger-event (concat "book:showing-details:" @book.id) @book}}>
        ...
    </div>
{{/if}}

Compatibility

  • Ember.js v3.28 or above
  • Ember CLI v3.28 or above
  • Node.js v14 or above

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.