mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 16:37:13 +02:00
Remove the "create" funtion from the Resource JS class
The original thought was that the actions you can do on a resource is: - create it - read it - update it (I guess you should have "delete" as well, but that isn't currently there) Although we use "read" and "update", we never use "create". So having it goes against the YAGNI principle :) Also, it had a bug: when sending a "create", the opt_newId in send_() would permanentily change the uri of the request, causing any subsequent request to go to the wrong endpoint. By removing the "create" we can simplify the rest of the code (the send_() function). ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=213029499
This commit is contained in:
parent
8ddbf88151
commit
cdcd5c2a0e
1 changed files with 5 additions and 22 deletions
|
@ -39,8 +39,8 @@ goog.inherits(registry.Resource, registry.Session);
|
||||||
/**
|
/**
|
||||||
* Get the resource from the server.
|
* Get the resource from the server.
|
||||||
*
|
*
|
||||||
* @param {!Object} args Params for server. Do not set the 'op' field on args.
|
* @param {!Object} args Params for server.
|
||||||
* @param {!Function} callback For retrieved resource.
|
* @param {!Function} callback for retrieved resource.
|
||||||
*/
|
*/
|
||||||
registry.Resource.prototype.read = function(args, callback) {
|
registry.Resource.prototype.read = function(args, callback) {
|
||||||
this.send_('read', args, callback);
|
this.send_('read', args, callback);
|
||||||
|
@ -48,22 +48,9 @@ registry.Resource.prototype.read = function(args, callback) {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the resource on the server.
|
* Update the resource on the server.
|
||||||
*
|
*
|
||||||
* @param {!Object} args params for server. Do not set the 'op' field on args.
|
* @param {!Object} args params for server.
|
||||||
* @param {!Function} callback on success.
|
|
||||||
* @param {string} newId name for the new resource.
|
|
||||||
* @throws {!Exception} if the 'op' field is set on args.
|
|
||||||
*/
|
|
||||||
registry.Resource.prototype.create = function(args, callback, newId) {
|
|
||||||
this.send_('create', args, callback, newId);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the resource on the server.
|
|
||||||
*
|
|
||||||
* @param {!Object} args params for server. Do not set the 'op' field on args.
|
|
||||||
* @param {!Function} callback on success.
|
* @param {!Function} callback on success.
|
||||||
* @throws {!Exception} if the 'op' field is set on args.
|
* @throws {!Exception} if the 'op' field is set on args.
|
||||||
*/
|
*/
|
||||||
|
@ -78,17 +65,13 @@ registry.Resource.prototype.update = function(args, callback) {
|
||||||
* @param {string} opCode One of (create|read|update)
|
* @param {string} opCode One of (create|read|update)
|
||||||
* @param {!Object} argsObj arguments for the operation.
|
* @param {!Object} argsObj arguments for the operation.
|
||||||
* @param {!Function} callback For XhrIo result throws.
|
* @param {!Function} callback For XhrIo result throws.
|
||||||
* @param {string=} opt_newId name for the new resource.
|
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
registry.Resource.prototype.send_ =
|
registry.Resource.prototype.send_ =
|
||||||
function(opCode, argsObj, callback, opt_newId) {
|
function(opCode, argsObj, callback) {
|
||||||
// NB: must be declared this way in order to avoid compiler renaming
|
// NB: must be declared this way in order to avoid compiler renaming
|
||||||
var req = {};
|
var req = {};
|
||||||
req['op'] = opCode;
|
req['op'] = opCode;
|
||||||
req['args'] = argsObj;
|
req['args'] = argsObj;
|
||||||
if (opt_newId) {
|
|
||||||
this.uri.setPath(this.uri.getPath() + '/' + opt_newId);
|
|
||||||
}
|
|
||||||
this.sendXhrIo(goog.json.serialize(req), callback);
|
this.sendXhrIo(goog.json.serialize(req), callback);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue