Răsfoiți Sursa

clean up setEvents/unsetEvents/resetEvents

Adam Shaw 8 ani în urmă
părinte
comite
8fe9447e97
1 a modificat fișierele cu 25 adăugiri și 8 ștergeri
  1. 25 8
      src/common/View.js

+ 25 - 8
src/common/View.js

@@ -352,11 +352,7 @@ var View = FC.View = Model.extend({
 
 
 	bindEventChanges: function() {
-		var _this = this;
-
-		this.listenTo(this.calendar, 'eventsReset', function(events) {
-			_this.resetEvents(events);
-		});
+		this.listenTo(this.calendar, 'eventsReset', this.resetEvents);
 	},
 
 
@@ -365,13 +361,34 @@ var View = FC.View = Model.extend({
 	},
 
 
+	setEvents: function(events) {
+		this.set('currentEvents', events);
+
+		if (this.has('displayingEvents')) {
+			this.requestEventsRender(events);
+		}
+	},
+
+
+	unsetEvents: function() {
+		this.unset('currentEvents');
+
+		if (this.has('displayingEvents')) {
+			this.requestEventsUnrender();
+		}
+	},
+
+
 	resetEvents: function(events) {
 		var _this = this;
 
 		this.set('currentEvents', events);
 
 		if (this.has('displayingEvents')) {
-			this.renderQueue.queue(function() { // TODO: move to below section?
+
+			// queue 2 render actions, guarantees serial execution.
+			// TODO: move this into rendering section?
+			this.renderQueue.queue(function() {
 				_this.executeEventsUnrender();
 			}, function() {
 				_this.executeEventsRender(events);
@@ -1249,11 +1266,11 @@ View.watch('initialEvents', [ 'dateProfile' ], function(deps) {
 
 
 View.watch('bindingEvents', [ 'initialEvents' ], function(deps) {
-	this.set('currentEvents', deps.initialEvents);
+	this.setEvents(deps.initialEvents);
 	this.bindEventChanges();
 }, function() {
 	this.unbindEventChanges();
-	this.unset('currentEvents');
+	this.unsetEvents();
 });