1.0.0 • Published 6 years ago

ember-controller-lifecycle v1.0.0

Weekly downloads
253
License
MIT
Repository
github
Last release
6 years ago

ember-controller-lifecycle

Greenkeeper badge npm version Build Status Ember Version

Add route lifecycle hooks to a route's controller

Motivation

If you want to reset state on your controller, you must override route hooks/events like so:

import Ember from 'ember';

export default Ember.Route.extend({
  setupController(controller) {
    this._super(...arguments);

    controller.set('foo', null);
    controller.set('bar', Ember.A());
  }
});

This couples a controller's private state to its route's code. You might then create a convention where you put controller setup code in its own function that you call from the route:

import Ember from 'ember';

export default Ember.Route.extend({
  setupController(controller) {
    this._super(...arguments);

    controller.setup();
  }
});
import Ember from 'ember';

export default Ember.Controller.extend({
  setup() {
    this.set('foo', null);
    this.set('bar', Ember.A());
  }
});

This addon functions the same way, it just eliminates the boilerplate by calling the hooks automatically.

Installation

ember install ember-controller-lifecycle

Usage

import Ember from 'ember';

export default Ember.Controller.extend({
  // https://www.emberjs.com/api/classes/Ember.Route.html#method_setupController
  setup(model) {
  },

  // https://www.emberjs.com/api/classes/Ember.Route.html#method_resetController
  reset(isExiting, transition) {
  }
});

The hooks are automatically installed into every controller.

Contributing

Installation

  • git clone <repository-url>
  • cd ember-controller-lifecycle
  • npm install

Linting

  • npm run lint:js
  • npm run lint:js -- --fix

Running tests

  • ember test – Runs the test suite on the current Ember version
  • ember test --server – Runs the test suite in "watch mode"
  • ember try:each – Runs the test suite against multiple Ember versions

Running the dummy application

For more information on using ember-cli, visit https://ember-cli.com/.

License

This project is licensed under the MIT License.

1.0.0

6 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago