From cdcd5c2a0ee1df98bda91e58074167f3993d29c2 Mon Sep 17 00:00:00 2001 From: guyben Date: Fri, 14 Sep 2018 13:01:11 -0700 Subject: [PATCH] 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 --- java/google/registry/ui/js/resource.js | 27 +++++--------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/java/google/registry/ui/js/resource.js b/java/google/registry/ui/js/resource.js index f01105a00..c58bfe5ea 100644 --- a/java/google/registry/ui/js/resource.js +++ b/java/google/registry/ui/js/resource.js @@ -39,8 +39,8 @@ goog.inherits(registry.Resource, registry.Session); /** * Get the resource from the server. * - * @param {!Object} args Params for server. Do not set the 'op' field on args. - * @param {!Function} callback For retrieved resource. + * @param {!Object} args Params for server. + * @param {!Function} callback for retrieved resource. */ registry.Resource.prototype.read = function(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 {!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 {!Object} args params for server. * @param {!Function} callback on success. * @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 {!Object} argsObj arguments for the operation. * @param {!Function} callback For XhrIo result throws. - * @param {string=} opt_newId name for the new resource. * @private */ 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 var req = {}; req['op'] = opCode; req['args'] = argsObj; - if (opt_newId) { - this.uri.setPath(this.uri.getPath() + '/' + opt_newId); - } this.sendXhrIo(goog.json.serialize(req), callback); };