diff --git a/CHANGELOG.md b/CHANGELOG.md index 35d050a..bce8e0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Change Log +* [#1](https://github.com/lozjackson/ember-auto-save/pull/1) Add `immediate` option to the `save()` method. + ### v0.0.4 2016-08-15 * [BUGFIX] If the `model` has no `save` method, try `model.content`. diff --git a/addon/utils/save.js b/addon/utils/save.js index 25c4c2e..c8775b1 100644 --- a/addon/utils/save.js +++ b/addon/utils/save.js @@ -54,8 +54,10 @@ const { assert, get } = Ember; @method save @param {Object} model The model to save @param {Integer} time The time to wait before saving. + @param {Boolean} immediate Trigger the function on the leading instead + of the trailing edge of the wait interval. Defaults to false. */ -export default function(model, time) { +export default function(model, time, immediate) { if ( isNaN(time) || time < 0 ) { time = 2000; } assert(`'model' should be an object`, typeof model === 'object'); @@ -66,5 +68,5 @@ export default function(model, time) { } assert(`'model.save' should be a function`, typeof model.save === 'function'); - Ember.run.debounce(model, model.save, time); + Ember.run.debounce(model, model.save, time, immediate); }