Skip to content

Instantly share code, notes, and snippets.

@Ziaw
Created July 13, 2011 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ziaw/1080078 to your computer and use it in GitHub Desktop.
Save Ziaw/1080078 to your computer and use it in GitHub Desktop.
function DataGate() {
var loadOne = function (url, ctor, callback) {
$.getJSON(url, function (model) {
var result = new ctor(model);
callback(result);
});
};
var loadMany = function (url, ctor, callback) {
$.getJSON(url, function (model) {
var result = $.map(model, function (p) { return new ctor(p); });
callback(result);
});
};
this.getProducts = function (callback) {
loadMany('/Products/Index/', Product, callback);
};
this.getProduct = function (productId, callback) {
loadOne('/Products/Details/' + productId, Product, callback);
};
this.getProductIssues = function (productId, callback) {
loadMany('/Issues/Index/' + productId, Issue, callback);
};
this.getIssueStories = function (issueId, callback) {
loadMany('/Stories/Index/' + issueId, Story, callback);
};
this.getStoryBlocks = function (storyId, callback) {
loadMany('/StoryBlocks/Index/' + storyId, StoryBlock, callback);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment