From 93a0b6b944c3bedc4ea81dc50f2e29dfc13913bb Mon Sep 17 00:00:00 2001 From: Jarrod Seccombe Date: Tue, 10 May 2016 10:59:25 -0400 Subject: [PATCH] Release 1.0.7 - Fixes version timeout, fixes break after first failure (#15) clear setTimeout when component is destroyed Should not stop updating if one request fails --- .../new-version-notifier/component.js | 19 ++++++++++++------- bower.json | 4 ++-- package.json | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/addon/components/new-version-notifier/component.js b/addon/components/new-version-notifier/component.js index 10a6c8b..ce72321 100644 --- a/addon/components/new-version-notifier/component.js +++ b/addon/components/new-version-notifier/component.js @@ -38,22 +38,23 @@ export default Ember.Component.extend({ Ember.$.ajax(self.get('url'), { cache:false }).then(function(res){ var currentVersion = self.get('version'); var newVersion = res && res.trim(); - + if (currentVersion && self.compareVersions(newVersion, currentVersion) === -1) { var message = self.get("updateMessage") .replace("{{oldVersion}}",currentVersion) .replace("{{newVersion}}",newVersion); - + self.setProperties({ message, lastVersion: currentVersion }); } - + self.set('version',newVersion); - self.set('_timeout',setTimeout(function() { - self.updateVersion(); - },self.get('updateInterval'))); + }).always(function() { + self.set('_timeout', setTimeout(function() { + self.updateVersion(); + }, self.get('updateInterval'))); }); }, 10); self.set('_timeout', t); @@ -78,11 +79,15 @@ export default Ember.Component.extend({ return 0; }, + willDestroy() { + this._super(...arguments); + clearTimeout(this.get('_timeout')); + }, actions: { reload() { location.reload(); }, - + close() { this.set('message', undefined); } diff --git a/bower.json b/bower.json index 67c9631..f4c6f76 100644 --- a/bower.json +++ b/bower.json @@ -9,8 +9,8 @@ "ember-qunit": "0.4.16", "ember-qunit-notifications": "0.1.0", "ember-resolver": "~0.1.20", - "jquery": "^1.11.3", + "jquery": "1.11.3", "loader.js": "ember-cli/loader.js#3.4.0", "qunit": "~1.20.0" } -} \ No newline at end of file +} diff --git a/package.json b/package.json index 5edba14..9e52df8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ember-cli-new-version", - "version": "1.0.6", + "version": "1.0.7", "description": "A convention based update notification for Ember. With this addon, you can detect a new version and notify the user to refresh the page", "directories": { "doc": "doc",