Created
March 30, 2015 14:37
-
-
Save foxdonut/a87d5ef9e259c48ae679 to your computer and use it in GitHub Desktop.
more wire code
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
module.exports = function() { | |
var browser = require("rest/browser"); | |
var mime = require("rest/interceptor/mime"); | |
var client = browser.wrap(mime, { mime: "application/json" }); | |
return client; | |
}; |
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
module.exports = { | |
//$plugins: [ { module: require("rest/wire") } ], | |
client: { | |
create: { | |
module: require("./client") | |
} | |
}, | |
stir: { | |
create: { | |
module: require("./stir"), | |
args: { $ref: "client" } | |
} | |
} | |
}; |
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
/* see also: https://github.com/briancavalier/fabulous/blob/master/rest.js */ | |
var when = require("when"); | |
module.exports = function(client) { | |
return function(baseUrl) { | |
return { | |
query: function(params) { | |
console.log("query:", params); | |
return client({ | |
method: "GET", | |
path: baseUrl, | |
params: params | |
}); | |
}, | |
get: function(id) { | |
console.log("get:", id); | |
return client({ | |
method: "GET", | |
path: baseUrl + "/" + id | |
}); | |
}, | |
save: function(model) { | |
console.log("save:", model); | |
if (model) { | |
var request = (model.id) ? { | |
method: "PUT", | |
path: baseUrl + "/" + model.id | |
} : { | |
method: "POST", | |
path: baseUrl | |
}; | |
request.entity = model; | |
return client(request); | |
} | |
return when.reject(); | |
}, | |
"delete": function(model) { | |
console.log("delete:", model); | |
return client({ | |
method: "DELETE", | |
path: baseUrl + "/" + model.id | |
}); | |
}, | |
getEntity: function(response) { | |
return response.entity; | |
} | |
}; | |
}; | |
}; |
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
var ko = require("knockout"); | |
var books = ko.observableArray(); | |
module.exports = { | |
books: books, | |
deleteBook: function(book) { | |
console.log("deleteBook:", book); | |
books.remove(book); | |
return book; | |
}, | |
log: function(value) { | |
console.log("logged!"); | |
return value; | |
}, | |
addBook: function(book) { | |
this.books.push(book); | |
} | |
}; |
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
var _ = require("lodash"); | |
module.exports = _.extend( | |
require("../../resource/wire-spec"), { | |
bookResource: { | |
create: { $ref: "stir", args: "/books" }, | |
ready: "query" | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment