From 7ea46bb3705f6c82cd593ea2543db6043820241c Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Sat, 10 Jun 2023 19:29:58 +0300 Subject: [PATCH] ref --- client/src/collection.js | 1 + client/src/model.js | 32 +++++++++++++++----------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/client/src/collection.js b/client/src/collection.js index 461165e689..23ab91694f 100644 --- a/client/src/collection.js +++ b/client/src/collection.js @@ -348,6 +348,7 @@ const Collection = Dep.extend(/** @lends Collection# */ { /** * Parse a response from the backend. * + * @todo Rename to `handleResponse`. * @param {Object} response A response. * @param {Object} options Options. * @returns {Collection[]} diff --git a/client/src/model.js b/client/src/model.js index 1d623317d6..b2aa3c4ba6 100644 --- a/client/src/model.js +++ b/client/src/model.js @@ -165,13 +165,13 @@ class Model { } /** - * @todo Revise naming. - * - * @public + * @deprecated Use `getClonedAttributesInstead`. * @return {Object.} */ toJSON() { - return Espo.Utils.cloneDeep(this.attributes); + console.warn(`model.toJSON is deprecated. Use 'getClonedAttributes' instead.`); + + return this.getClonedAttributes(); } /** @@ -205,7 +205,7 @@ class Model { } const data = model && ['create', 'update', 'patch'].includes(method) ? - (options.attributes || model.toJSON()) : null; + (options.attributes || model.getClonedAttributes()) : null; let error = options.error; @@ -461,14 +461,12 @@ class Model { * @fires Model#sync */ fetch(options) { - options = {...options, parse: true}; + options = {...options}; let success = options.success; options.success = response => { - let serverAttributes = options.parse ? - this.parse(response, options) : - response; + let serverAttributes = this.handleResponse(response, options); if (!this.set(serverAttributes, options)) { return false; @@ -499,7 +497,7 @@ class Model { * @copyright Credits to Backbone.js. */ save(attributes, options) { - options = {...options, parse: true}; + options = {...options}; if (attributes && !options.wait) { this.setMultiple(attributes, options); @@ -512,9 +510,7 @@ class Model { options.success = response => { this.attributes = attributes; - let responseAttributes = options.parse ? - this.parse(response, options) : - response; + let responseAttributes = this.handleResponse(response, options); if (options.wait) { responseAttributes = {...attributes, ...responseAttributes}; @@ -644,12 +640,14 @@ class Model { } /** + * Handle a response to set + * * @protected - * @param {*} response - * @param {Object.} options - * @return {*} + * @param {*} response A response from the backend. + * @param {Object.} options Options. + * @return {*} Attributes. */ - parse(response, options) { + handleResponse(response, options) { return response; }