Created
September 26, 2013 22:19
-
-
Save ryanflorence/6721394 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why is {RSVP} wrapped in curly braces?