Skip to content

Commit 6f3d25b

Browse files
committed
Refactor fetch.
1 parent cbfee37 commit 6f3d25b

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

lib/object.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -769,30 +769,26 @@
769769
* Fetch the model from the server. If the server's representation of the
770770
* model differs from its current attributes, they will be overriden,
771771
* triggering a <code>"change"</code> event.
772+
* @param {Object} fetchOptions Optional options to set 'keys' and
773+
* 'include' option.
772774
* @param {Object} options Optional Backbone-like options object to be
773-
* passed in to set. Also you can set 'keys' and 'include' options.
775+
* passed in to set.
774776
* @return {AV.Promise} A promise that is fulfilled when the fetch
775777
* completes.
776778
*/
777-
fetch: function(options) {
778-
var include = null;
779-
var keys = null;
780-
if(options) {
781-
var processOpt = function(k) {
782-
if(options[k]){
783-
if(_.isArray(options[k])) {
784-
return options[k].join(',');
785-
} else {
786-
return options[k];
787-
}
788-
}
789-
};
790-
include = processOpt('include');
791-
keys = processOpt('keys');
779+
fetch: function() {
780+
var options = null;
781+
var fetchOptions = {};
782+
if(arguments.length == 1) {
783+
options = arguments[0];
784+
} else if(arguments.length == 2) {
785+
fetchOptions = arguments[0];
786+
options = arguments[1];
792787
}
788+
793789
var self = this;
794790
var request = AV._request("classes", this.className, this.id, 'GET',
795-
{ include: include, keys: keys});
791+
fetchOptions);
796792
return request.then(function(response, status, xhr) {
797793
self._finishFetch(self.parse(response, status, xhr), true);
798794
return self;

0 commit comments

Comments
 (0)