Skip to content

Instantly share code, notes, and snippets.

@brianarn
Last active December 17, 2015 13:10
Show Gist options
  • Save brianarn/5615467 to your computer and use it in GitHub Desktop.
Save brianarn/5615467 to your computer and use it in GitHub Desktop.
Extended dojo/store/JsonRest with ability to mutate the server response
define([
"dojo/_base/declare",
"dojo/store/JsonRest",
"dojo/store/util/QueryResults"
], function(declare, JsonRest, QueryResults){
return declare(JsonRest, {
query: function(query, queryOptions){
// Issue original query
var results = this.inherited(arguments);
// Using the promise-driven nature of queries,
// and then returning a promise,
// basically deref and provide the items,
// wrapped in the QueryResults API as store consumers expect
var itemsPromise = results.then(function(data){
return data.items;
});
return QueryResults(itemsPromise);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment