Browse Source

cleanup data_as_a_function code

Adam Shaw 12 năm trước cách đây
mục cha
commit
1c802475ea
1 tập tin đã thay đổi với 15 bổ sung5 xóa
  1. 15 5
      src/EventManager.js

+ 15 - 5
src/EventManager.js

@@ -136,13 +136,22 @@ function EventManager(options, _sources) {
 				var success = source.success;
 				var error = source.error;
 				var complete = source.complete;
-				var custom_data;
+
+				// retrieve any outbound GET/POST $.ajax data from the options
+				var customData;
 				if ($.isFunction(source.data)) {
-					custom_data = source.data();
-				} else {
-					custom_data = source.data;
+					// supplied as a function that returns a key/value object
+					customData = source.data();
+				}
+				else {
+					// supplied as a straight key/value object
+					customData = source.data;
 				}
-				var data = $.extend({}, custom_data || {});
+
+				// use a copy of the custom data so we can modify the parameters
+				// and not affect the passed-in object.
+				var data = $.extend({}, customData || {});
+
 				var startParam = firstDefined(source.startParam, options.startParam);
 				var endParam = firstDefined(source.endParam, options.endParam);
 				if (startParam) {
@@ -151,6 +160,7 @@ function EventManager(options, _sources) {
 				if (endParam) {
 					data[endParam] = Math.round(+rangeEnd / 1000);
 				}
+
 				pushLoading();
 				$.ajax($.extend({}, ajaxDefaults, source, {
 					data: data,