ember-auto-save
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -1,4 +0,5 @@ | ||
import AutoSaveProxy, { save } from 'ember-auto-save/utils/auto-save'; | ||
import AutoSaveProxy from 'ember-auto-save/utils/auto-save'; | ||
import save from 'ember-auto-save/utils/auto-save'; | ||
export default AutoSaveProxy; | ||
export { save }; |
@@ -5,11 +5,22 @@ /** | ||
import Ember from 'ember'; | ||
import save from 'ember-auto-save/utils/save'; | ||
/** | ||
This auto-save mixin overrides the `setUnknownProperty` method, and | ||
triggers the `save` method when properties are set on the model. | ||
This auto-save mixin overrides the `setUnknownProperty` method, and | ||
triggers the `save()` method when properties are set on the model. | ||
Use this mixin with an ObjectProxy - Wrap the model in the ObjectProxy. | ||
The example below show how to create an `autoSaveProxy` object. | ||
@class AutoSaveMixin | ||
@namespace Mixins | ||
``` | ||
import AutoSaveMixin from 'ember-auto-save/mixins/auto-save'; | ||
let AutoSaveProxy = Ember.ObjectProxy.extend(AutoSaveMixin); | ||
let autoSaveProxy = AutoSaveProxy.create({ | ||
content: this.get('model') | ||
}); | ||
``` | ||
@class AutoSaveMixin | ||
@namespace Mixins | ||
*/ | ||
@@ -49,5 +60,5 @@ export default Ember.Mixin.create({ | ||
save() { | ||
let { content:model, wait } = this.getProperties('content', 'wait'); | ||
Ember.run.debounce(model, model.save, wait); | ||
let { content, wait } = this.getProperties('content', 'wait'); | ||
save(content, wait); | ||
} | ||
}); |
@@ -7,6 +7,29 @@ /** | ||
const { computed, assert } = Ember; | ||
const { computed } = Ember; | ||
const AutoSaveProxy = Ember.ObjectProxy.extend(AutoSaveMixin); | ||
/** | ||
The `AutoSave` utility class provides the `autoSaveProxy` computed property. | ||
This property can be used in controllers or components and will proxy `get`/`set` | ||
requests to the `model`. Setting properties on the `AutoSaveProxy` object will | ||
trigger an automatic save to be scheduled after a short delay. | ||
controller/component | ||
``` | ||
import Ember from 'ember'; | ||
import autoSaveProxy from 'ember-auto-save'; | ||
export default Ember.Controller.extend({ | ||
autoSaveProxy, | ||
model: model | ||
}); | ||
``` | ||
template | ||
``` | ||
{{input value=autoSaveProxy.name}} | ||
``` | ||
@class AutoSave | ||
@@ -54,37 +77,1 @@ @namespace Utils | ||
}); | ||
/** | ||
## Save | ||
This method debounces the 'save' method on the model provided. This method is | ||
useful for saving models from within code by calling `save(model)`. | ||
Using this method you don't need to wrap your models in an ObjectProxy. | ||
NOTE: This method does not auto-save, you have to manually call this method. | ||
``` | ||
import { save } from `ember-auto-save` | ||
save( model ); | ||
``` | ||
Optionally, you can provide a time to wait before applying the method. If no | ||
time value is specified then the default of 2000 (2 seconds) will be used. | ||
``` | ||
// save the model after 5 seconds | ||
save( model, 5000 ); | ||
``` | ||
@method save | ||
@param {Object} model The model to save | ||
@param {Integer} time The time to wait before saving. | ||
*/ | ||
export function save(model, time) { | ||
if ( isNaN(time) || time < 0 ) { time = 2000; } | ||
assert(`'model' should be an object`, typeof model === 'object'); | ||
assert(`'model.save' should be a function`, typeof model.save === 'function'); | ||
Ember.run.debounce(model, model.save, time); | ||
} |
@@ -1,1 +0,1 @@ | ||
export { default, save } from 'ember-auto-save/utils/auto-save'; | ||
export { default } from 'ember-auto-save/utils/auto-save'; |
@@ -6,3 +6,4 @@ YUI.add("yuidoc-meta", function(Y) { | ||
"Mixins.AutoSaveMixin", | ||
"Utils.AutoSave" | ||
"Utils.AutoSave", | ||
"Utils.Save" | ||
], | ||
@@ -9,0 +10,0 @@ "modules": [ |
@@ -6,3 +6,3 @@ { | ||
"url": "https://github.com/lozjackson/ember-auto-save", | ||
"version": "0.0.1" | ||
"version": "0.0.2" | ||
}, | ||
@@ -44,2 +44,13 @@ "files": { | ||
} | ||
}, | ||
"addon/utils/save.js": { | ||
"name": "addon/utils/save.js", | ||
"modules": {}, | ||
"classes": { | ||
"Utils.Save": 1 | ||
}, | ||
"fors": {}, | ||
"namespaces": { | ||
"Utils": 1 | ||
} | ||
} | ||
@@ -54,3 +65,4 @@ }, | ||
"Mixins.AutoSaveMixin": 1, | ||
"Utils.AutoSave": 1 | ||
"Utils.AutoSave": 1, | ||
"Utils.Save": 1 | ||
}, | ||
@@ -64,4 +76,4 @@ "fors": {}, | ||
"tag": "module", | ||
"file": "addon/utils/auto-save.js", | ||
"line": 10 | ||
"file": "addon/utils/save.js", | ||
"line": 8 | ||
} | ||
@@ -95,4 +107,4 @@ }, | ||
"file": "addon/mixins/auto-save.js", | ||
"line": 6, | ||
"description": "This auto-save mixin overrides the `setUnknownProperty` method, and\ntriggers the `save` method when properties are set on the model.\n\nUse this mixin with an ObjectProxy - Wrap the model in the ObjectProxy." | ||
"line": 7, | ||
"description": "This auto-save mixin overrides the `setUnknownProperty` method, and\ntriggers the `save()` method when properties are set on the model.\n\nThe example below show how to create an `autoSaveProxy` object.\n\n```\nimport AutoSaveMixin from 'ember-auto-save/mixins/auto-save';\n\nlet AutoSaveProxy = Ember.ObjectProxy.extend(AutoSaveMixin);\n\nlet autoSaveProxy = AutoSaveProxy.create({\n content: this.get('model')\n});\n```" | ||
}, | ||
@@ -110,3 +122,18 @@ "Utils.AutoSave": { | ||
"file": "addon/utils/auto-save.js", | ||
"line": 10 | ||
"line": 10, | ||
"description": "The `AutoSave` utility class provides the `autoSaveProxy` computed property.\nThis property can be used in controllers or components and will proxy `get`/`set`\nrequests to the `model`. Setting properties on the `AutoSaveProxy` object will\ntrigger an automatic save to be scheduled after a short delay.\n\ncontroller/component\n\n```\nimport Ember from 'ember';\nimport autoSaveProxy from 'ember-auto-save';\n\nexport default Ember.Controller.extend({\n\tautoSaveProxy,\n\tmodel: model\n});\n```\n\ntemplate\n\n```\n{{input value=autoSaveProxy.name}}\n ```" | ||
}, | ||
"Utils.Save": { | ||
"name": "Utils.Save", | ||
"shortname": "Utils.Save", | ||
"classitems": [], | ||
"plugins": [], | ||
"extensions": [], | ||
"plugin_for": [], | ||
"extension_for": [], | ||
"module": "ember-auto-save", | ||
"namespace": "Utils", | ||
"file": "addon/utils/save.js", | ||
"line": 8, | ||
"description": "The `Save` Utility class provides a method for saving the model using the [Ember.js debounce method](http://emberjs.com/api/classes/Ember.run.html#method_debounce).\n\n```\nimport { save } from `ember-auto-save`\n\nsave(model);\n```\n\nOptionally, you can provide a time to wait before applying the method. If no\ntime value is specified then the default of 2000 (2 seconds) will be used.\n\n```\n// save the model after 5 seconds\nsave(model, 5000);\n```" | ||
} | ||
@@ -137,3 +164,3 @@ }, | ||
"file": "addon/mixins/auto-save.js", | ||
"line": 17, | ||
"line": 28, | ||
"description": "The number of milliseconds to wait for debouncing", | ||
@@ -150,3 +177,3 @@ "itemtype": "property", | ||
"file": "addon/mixins/auto-save.js", | ||
"line": 26, | ||
"line": 37, | ||
"description": "Set property, and call save.", | ||
@@ -179,3 +206,3 @@ "itemtype": "method", | ||
"file": "addon/mixins/auto-save.js", | ||
"line": 41, | ||
"line": 52, | ||
"description": "Save the underlying record, debouncing with the interval defined in `wait`.", | ||
@@ -192,3 +219,3 @@ "itemtype": "method", | ||
"file": "addon/utils/auto-save.js", | ||
"line": 15, | ||
"line": 38, | ||
"description": "## AutoSaveProxy\n\nThis is a computed property that provides an `autoSaveProxy` object. The `autoSaveProxy`\nobject will proxy all requests to the `model` property. Setting properties on the\n`autoSaveProxy` object will be automatically saved.\n\nUse this property in a controller or component. Set your `model` on the\ncontroller, then create an `autoSaveProxy` object for the model.\n\n Example:\n\ncontroller.js\n\n```\nimport Ember from 'ember';\nimport autoSaveProxy from 'ember-auto-save';\n\nexport default Ember.Controller.extend({\n\tautoSaveProxy,\n\tmodel: model\n});\n```\n\ntemplate.hbs\n\n```\n{{input value=autoSaveProxy.name}}\n ```", | ||
@@ -203,5 +230,5 @@ "itemtype": "property", | ||
{ | ||
"file": "addon/utils/auto-save.js", | ||
"line": 54, | ||
"description": "## Save\n\nThis method debounces the 'save' method on the model provided. This method is\nuseful for saving models from within code by calling `save(model)`.\n\nUsing this method you don't need to wrap your models in an ObjectProxy.\n\nNOTE: This method does not auto-save, you have to manually call this method.\n\n\n ```\nimport { save } from `ember-auto-save`\n\nsave( model );\n ```\n\nOptionally, you can provide a time to wait before applying the method. If no\ntime value is specified then the default of 2000 (2 seconds) will be used.\n\n ```\n// save the model after 5 seconds\nsave( model, 5000 );\n ```", | ||
"file": "addon/utils/save.js", | ||
"line": 29, | ||
"description": "This method debounces the `save()` method on the `model` provided. This method is\nuseful for saving models from within code by calling `save(model)`.\n\nUsing this method you don't need to wrap your models in an ObjectProxy.\n\n See the Ember.js API docs for more information on the [debounce method](http://emberjs.com/api/classes/Ember.run.html#method_debounce).\n\nNOTE: This method does not auto-save, you have to manually call this method.\n\n\n ```\nimport { save } from `ember-auto-save`\n\nsave(model);\n ```\n\nOptionally, you can provide a time to wait before applying the method. If no\ntime value is specified then the default of 2000 (2 seconds) will be used.\n\n ```\n// save the model after 5 seconds\nsave(model, 5000);\n ```", | ||
"itemtype": "method", | ||
@@ -221,3 +248,3 @@ "name": "save", | ||
], | ||
"class": "Utils.AutoSave", | ||
"class": "Utils.Save", | ||
"module": "ember-auto-save", | ||
@@ -224,0 +251,0 @@ "namespace": "Utils" |
{ | ||
"name": "ember-auto-save", | ||
"version": "0.0.1", | ||
"description": "Ember auto save", | ||
"version": "0.0.2", | ||
"description": "An Ember-cli addon that provides auto-save functionality for Ember applications.", | ||
"directories": { | ||
@@ -6,0 +6,0 @@ "doc": "doc", |
# Ember-auto-save | ||
An Ember-cli addon that provides auto-save functionality for ember-data models. | ||
An Ember-cli addon that provides auto-save functionality for Ember applications. | ||
@@ -72,8 +72,6 @@ ## Demo | ||
This method debounces the `save` method on the `model` provided. This method is | ||
useful for saving models from within code by calling `save(model)`. | ||
Use the `save()` method to save the `model` using the | ||
Ember.js [debounce()](http://emberjs.com/api/classes/Ember.run.html#method_debounce) | ||
method. | ||
NOTE: This method does not auto-save the `model`, you have to manually call this method. | ||
``` | ||
@@ -80,0 +78,0 @@ import { save } from `ember-auto-save` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
189334
48
1761
89