ember-data-route is built and maintained by DockYard, contact us for expert Ember.js consulting.
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.
npm install ember-data-route --save-dev
Add the mixin to any route you want:
import Ember from 'ember';
import DataRoute from 'ember-data-route';
export default Ember.Route.extend(DataRoute, {
...
});
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?");
}
});
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
.
We are very thankful for the many contributors
This library follows Semantic Versioning
Please do! We are always looking to improve this gem. Please see our Contribution Guidelines on how to properly submit issues and pull requests.
DockYard, Inc © 2014