Skip to content

Commit

Permalink
move mixin to standard location & add allowUnload
Browse files Browse the repository at this point in the history
 - Use the standard conventional location for ember-cli addon mixins.
 - Wrap "allow" logic into an overrideable method `allowUnload`
  • Loading branch information
ronco committed Dec 7, 2015
1 parent 264a199 commit 3fc97a1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
6 changes: 5 additions & 1 deletion addon/confirmation.js → addon/mixins/confirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@ export default Mixin.create({
return msg;
},

allowUnload(transition) {
return transition.targetName.indexOf(this.routeName + '.') === 0;
},

actions: {
willTransition(transition) {
this._super(...arguments);

let allow = transition.targetName.indexOf(this.routeName + '.') === 0;
const allow = this.allowUnload(transition);

if (!allow && this.canUnload()) {
const msg = this.readConfirmation();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-onbeforeunload",
"version": "0.1.0",
"version": "0.2.0",
"description": "An addon to conditionally prompt the user when transitioning between routes or closing the browser.",
"directories": {
"doc": "doc",
Expand Down
2 changes: 1 addition & 1 deletion tests/dummy/app/routes/foo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Ember from 'ember';
import ConfirmationMixin from 'ember-onbeforeunload/confirmation';
import ConfirmationMixin from 'ember-onbeforeunload/mixins/confirmation';

export default Ember.Route.extend(ConfirmationMixin, {
model() {
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/mixins/confirmation-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Ember from 'ember';
import ConfirmationMixin from 'ember-onbeforeunload/mixins/confirmation';
import { module, test } from 'qunit';

module('Unit | Mixin | confirmation');

// Replace this with your real tests.
test('it works', function(assert) {
let ConfirmationObject = Ember.Object.extend(ConfirmationMixin);
let subject = ConfirmationObject.create();
assert.ok(subject);
});

0 comments on commit 3fc97a1

Please sign in to comment.