Skip to content

Instantly share code, notes, and snippets.

@kuon
Created March 2, 2011 18:40
Show Gist options
  • Save kuon/851440 to your computer and use it in GitHub Desktop.
Save kuon/851440 to your computer and use it in GitHub Desktop.
fetch: function(S, query) {
var Q = SGIO.QUERIES;
console.log('fetch');
S.dataSourceDidFetchQuery(query); // We fetch all queries immediately, then we will push the new data
console.log(query);
if(query === Q.ALL_CLIENT) {
SC.Request.getUrl('/clients.json').json()
.notify(this, '_didFetchRecords', S, SGIO.Client)
.send();
}
return YES;
},
_didFetchRecords:function(response, S, recordType) {
if(SC.ok(response)) {
response.get('body').forEach(function(rec) {
var key = S.storeKeyFor(recordType, rec.id);
S.writeDataHash(key, rec, SC.Record.READY_CLEAN);
S.dataHashDidChange(key);
});
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment