Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Created September 26, 2013 22:19
Show Gist options
  • Save ryanflorence/6721394 to your computer and use it in GitHub Desktop.
Save ryanflorence/6721394 to your computer and use it in GitHub Desktop.
import DS from 'ember-data';
import {RSVP} from 'ember';
var Adapter = DS.RESTAdapter.extend({
namespace: 'api/v1',
findAll: function(store, type, sinceToken) {
var url = this.buildURL(type.typeKey);
var cached = localStorage.getItem(url);
if (cached) {
return new RSVP.Promise(function(resolve) {
this.ajax(url, 'GET').then(function(res) {
localStorage.setItem(url, JSON.stringify(res));
store.pushMany(type, res);
});
return resolve(JSON.parse(cached));
}.bind(this));
} else {
return this._super.apply(this, arguments).then(function(data, xhr) {
localStorage.setItem(url, JSON.stringify(data));
return data;
});
}
}
});
export default Adapter;
@assertchris
Copy link

Why is {RSVP} wrapped in curly braces?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment