Skip to content

Common teardown scenario for ember routes backed by a data model

License

Notifications You must be signed in to change notification settings

DavyJonesLocker/ember-data-route

Repository files navigation

Ember Data Route Build

ember-data-route is built and maintained by DockYard, contact us for expert Ember.js consulting.

About

Ensure you clean up after your models.

Any routes you deactivate will check the model to ensure it is not unsaved. If it is it will either rollback or remove the model from the store depending if has been previously persisted.

Install

npm install ember-data-route --save-dev

Usage

Add the mixin to any route you want:

import Ember from 'ember';
import DataRoute from 'ember-data-route';

export default Ember.Route.extend(DataRoute, {
  ...
});

Transition Confirmation

By default when you transition out of the route the data model is rolled-back/removed automatically after the router is deactivated. However, you may want to detect if this is going to happen and alert the user of changes that will be lost. Typically you could use window.confirm to allow the user to decide to proceed or not. In the route you are mixing into you can provide your own willTransitionConfirm function to handle this. By default this function returns true and is passed the transition object as an argument for you to handle. One possible override could be:

export default Ember.Route.extend(DataRouteMixin, {
  willTransitionConfirm() {
    return window.confirm("You have unsaved changes that will be lost. Do you want to continue?");
  }
});

Configuring Which Model

Sometimes model isn't the place where your primary model is located, so setting primaryModel to something else would allow you to override that setting.

export default Ember.Route.extend(DataRouteMixin, {
  primaryModel: 'user'
});

This will look on controller.user, instead of controller.model.

Authors

We are very thankful for the many contributors

Versioning

This library follows Semantic Versioning

Want to help?

Please do! We are always looking to improve this gem. Please see our Contribution Guidelines on how to properly submit issues and pull requests.

Legal

DockYard, Inc © 2014

@dockyard

Licensed under the MIT license

About

Common teardown scenario for ember routes backed by a data model

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published