Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jayphelps/ember-model-batch
Batch multiple model requests into a single ajax call (ember-data or ember-model)
https://github.com/jayphelps/ember-model-batch
Last synced: 21 days ago
JSON representation
Batch multiple model requests into a single ajax call (ember-data or ember-model)
- Host: GitHub
- URL: https://github.com/jayphelps/ember-model-batch
- Owner: jayphelps
- License: mit
- Created: 2013-11-01T05:57:23.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-05-26T17:44:02.000Z (over 9 years ago)
- Last Synced: 2024-04-14T18:07:14.894Z (7 months ago)
- Language: JavaScript
- Size: 145 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
ember-model-batch
=================Automatically batch multiple model requests, that happen within the same execution stack, into a single ajax call using the `Ember.AdapterBatchMixin` with your API adapter. (Usually `DS.RESTAdapter` or `Ember.RESTAdapter`)
Basically, if multiple models are synced at the same time, instead of making an ajax request for each one, make a single batch call. *This all assumes you have such ability within your API.*
### Ember Data Example
```javascript
App.ApplicationAdapter = DS.RESTAdapter.extend(Ember.AdapterBatchMixin, {
namespace: '/api/v1',
batch: function (requests) {
// make your single API call
}
});
```### Ember Model Example
```javascript
Ember.RESTAdapter.reopen(Ember.AdapterBatchMixin, {
batch: function (requests) {
// make your single API call
}
});
```##Usage
Because batch API paradigms aren't all the same, you'll need to implement the `batch` method on your adapter.This method will get called whenever multiple models are being synced to the server within the same `Ember.run` loop iteration.
Request argument format:
```javascript
[{
// The adapter's original ajax() method arguments
args: ,
// Call this function with the resolved data for this particular request
resolve:
// Call this function with the rejected data for this particular request
reject:
}]
```##Uhhh...I don't get it...
Yeah...I know. I made this for myself, so it's difficult to explain what this solves. Maybe I'll throw together an example using Facebooks Open Graph batch API? (open an issue request...)##License
MIT Licensed