Explorar el Código

eventRenderWait

Adam Shaw hace 9 años
padre
commit
a45d7dbe26
Se han modificado 3 ficheros con 10 adiciones y 5 borrados
  1. 8 4
      src/common/TaskQueue.js
  2. 1 1
      src/common/View.js
  3. 1 0
      src/defaults.js

+ 8 - 4
src/common/TaskQueue.js

@@ -1,11 +1,10 @@
 
 // TODO: write tests and clean up code
-// TODO: for debounce, always let current task finish
 
-function TaskQueue() {
+function TaskQueue(debounceWait) {
 	var q = []; // array of runFuncs
 
-	this.add = function(taskFunc) {
+	function addTask(taskFunc) {
 		return new Promise(function(resolve) {
 
 			// should run this function when it's taskFunc's turn to run.
@@ -31,7 +30,12 @@ function TaskQueue() {
 				runFunc();
 			}
 		});
-	};
+	}
+
+	this.add = // potentially debounce, for the public method
+		typeof debounceWait === 'number' ?
+			debounce(addTask, debounceWait) :
+			addTask; // if not a number (null/undefined/false), no debounce at all
 }
 
 FC.TaskQueue = TaskQueue;

+ 1 - 1
src/common/View.js

@@ -70,7 +70,7 @@ var View = FC.View = Class.extend(EmitterMixin, ListenerMixin, {
 		this.eventOrderSpecs = parseFieldSpecs(this.opt('eventOrder'));
 
 		this.dateRenderQueue = new TaskQueue();
-		this.eventRenderQueue = new TaskQueue();
+		this.eventRenderQueue = new TaskQueue(this.opt('eventRenderWait'));
 
 		this.initialize();
 	},

+ 1 - 0
src/defaults.js

@@ -82,6 +82,7 @@ Calendar.defaults = {
 	dropAccept: '*',
 
 	eventOrder: 'title',
+	//eventRenderWait: null,
 
 	eventLimit: false,
 	eventLimitText: 'more',