Adam Shaw 8 лет назад
Родитель
Сommit
2f1ca31635
2 измененных файлов с 111 добавлено и 109 удалено
  1. 1 11
      src/common/View.date-range.js
  2. 110 98
      src/common/View.js

+ 1 - 11
src/common/View.date-range.js

@@ -35,12 +35,7 @@ View.mixin({
 	------------------------------------------------------------------------------------------------------------------*/
 
 
-	isSameDateProfile: function(dateProfile) {
-		return this.activeRange && isRangesEqual(this.activeRange, dateProfile.activeRange);
-	},
-
-
-	setDateProfile: function(dateProfile) {
+	setDateProfileForRendering: function(dateProfile) {
 		this.currentRange = dateProfile.currentRange;
 		this.currentRangeUnit = dateProfile.currentRangeUnit;
 		this.renderRange = dateProfile.renderRange;
@@ -58,11 +53,6 @@ View.mixin({
 	},
 
 
-	unsetDateProfile: function() {
-		this.activeRange = null;
-	},
-
-
 	// Builds a structure with info about what the dates/ranges will be for the "prev" view.
 	buildPrevDateProfile: function(date) {
 		var prevDate = date.clone().startOf(this.currentRangeUnit).subtract(this.dateIncrement);

+ 110 - 98
src/common/View.js

@@ -264,42 +264,96 @@ var View = FC.View = Model.extend({
 
 
 	setDate: function(date) {
-		var dateProfile = this.buildDateProfile(date, null, true); // forceToValid=true
-
-		if (!this.isSameDateProfile(dateProfile)) {
-			this.setDateProfile(dateProfile);
-			this.set('dateProfile', dateProfile); // for watchers
+		var currentDateProfile = this.get('dateProfile');
+		var newDateProfile = this.buildDateProfile(date, null, true); // forceToValid=true
+
+		if (
+			!currentDateProfile ||
+			!isRangesEqual(currentDateProfile.activeRange, newDateProfile.activeRange)
+		) {
+			this.setDateProfile(newDateProfile);
 		}
 
-		return dateProfile.date;
+		return newDateProfile.date;
 	},
 
 
 	unsetDate: function() {
-		this.unsetDateProfile();
-		this.unset('dateProfile'); // for watchers
+		if (this.has('dateProfile')) {
+			this.unsetDateProfile();
+		}
+	},
+
+
+	setDateProfile: function(dateProfile) {
+		var _this = this;
+
+		// render first, so that dependants of dateProfile know rendering already happened
+		this.renderQueue.add(function() {
+			_this.executeDateRender(dateProfile);
+		});
+
+		this.set('dateProfile', dateProfile); // for watchers
 	},
 
 
-	// Date Render Queuing
+	unsetDateProfile: function() {
+		var _this = this;
+
+		this.unset('dateProfile'); // for watchers. let them react before unrendering.
+
+		this.renderQueue.add(function() {
+			_this.executeDateUnrender();
+		});
+	},
+
+
+	// Event Data
 	// -----------------------------------------------------------------------------------------------------------------
 
 
-	// if dateProfile not specified, uses current
-	requestDateRender: function(dateProfile) {
+	fetchInitialEvents: function(dateProfile) {
+		return this.calendar.requestEvents(
+			dateProfile.activeRange.start,
+			dateProfile.activeRange.end
+		);
+	},
+
+
+	bindEventChanges: function() {
 		var _this = this;
 
-		return this.renderQueue.add(function() {
-			return _this.executeDateRender(dateProfile);
+		this.listenTo(this.calendar, 'eventsReset', function(events) {
+			_this.setEvents(events);
 		});
 	},
 
 
-	requestDateUnrender: function() {
+	unbindEventChanges: function() {
+		this.stopListeningTo(this.calendar, 'eventsReset');
+		this.unsetEvents();
+	},
+
+
+	setEvents: function(events) {
+		var _this = this;
+
+		// render first, so that dependants of bindingEvents/currentEvents know rendering already happened
+		this.renderQueue.add(function() {
+			_this.executeEventsRender(events);
+		});
+
+		this.set('currentEvents', events); // for watchers
+	},
+
+
+	unsetEvents: function() {
 		var _this = this;
 
-		return this.renderQueue.add(function() {
-			return _this.executeDateUnrender();
+		this.unset('currentEvents'); // for watchers. let them react before unrendering.
+
+		this.renderQueue.add(function() {
+			_this.executeEventsUnrender();
 		});
 	},
 
@@ -311,23 +365,15 @@ var View = FC.View = Model.extend({
 	// if dateProfile not specified, uses current
 	executeDateRender: function(dateProfile) {
 
-		if (dateProfile) {
-			this.setDateProfile(dateProfile);
-		}
-
+		this.setDateProfileForRendering(dateProfile);
 		this.updateTitle();
 		this.calendar.updateToolbarButtons();
 
-		// if rendering a new date, reset scroll to initial state (scrollTime)
-		if (dateProfile) {
-			this.captureInitialScroll();
-		}
-		else {
-			this.captureScroll(); // a rerender of the current date
-		}
-
+		this.captureInitialScroll();
 		this.freezeHeight();
 
+		this.executeDateUnrender();
+
 		if (this.render) {
 			this.render(); // TODO: deprecate
 		}
@@ -346,19 +392,27 @@ var View = FC.View = Model.extend({
 
 
 	executeDateUnrender: function() {
-		this.unselect();
-		this.stopNowIndicator();
+		if (this.isDatesRendered) {
+			this.captureScroll();
+			this.freezeHeight();
 
-		this.trigger('before:datesUnrendered');
+			this.unselect();
+			this.stopNowIndicator();
 
-		this.unrenderBusinessHours();
-		this.unrenderDates();
+			this.trigger('before:datesUnrendered');
 
-		if (this.destroy) {
-			this.destroy(); // TODO: deprecate
-		}
+			this.unrenderBusinessHours();
+			this.unrenderDates();
+
+			if (this.destroy) {
+				this.destroy(); // TODO: deprecate
+			}
+
+			this.thawHeight();
+			this.releaseScroll();
 
-		this.isDatesRendered = false;
+			this.isDatesRendered = false;
+		}
 	},
 
 
@@ -693,29 +747,6 @@ var View = FC.View = Model.extend({
 	},
 
 
-	// Event Render Queuing
-	// -----------------------------------------------------------------------------------------------------------------
-
-
-	// assumes any previous event renders have been cleared already
-	requestEventsRender: function(events) {
-		var _this = this;
-
-		this.renderQueue.add(function() {
-			_this.executeEventsRender(events);
-		});
-	},
-
-
-	requestEventsUnrender: function() {
-		var _this = this;
-
-		this.renderQueue.addQuickly(function() {
-			_this.executeEventsUnrender();
-		});
-	},
-
-
 	// Event High-level Rendering
 	// -----------------------------------------------------------------------------------------------------------------
 
@@ -724,6 +755,8 @@ var View = FC.View = Model.extend({
 		this.captureScroll();
 		this.freezeHeight();
 
+		this.executeEventsUnrender();
+
 		this.renderEvents(events);
 
 		this.thawHeight();
@@ -735,21 +768,23 @@ var View = FC.View = Model.extend({
 
 
 	executeEventsUnrender: function() {
-		this.onBeforeEventsUnrender();
+		if (this.isEventsRendered) {
+			this.onBeforeEventsUnrender();
 
-		this.captureScroll();
-		this.freezeHeight();
+			this.captureScroll();
+			this.freezeHeight();
 
-		if (this.destroyEvents) {
-			this.destroyEvents(); // TODO: deprecate
-		}
+			if (this.destroyEvents) {
+				this.destroyEvents(); // TODO: deprecate
+			}
 
-		this.unrenderEvents();
+			this.unrenderEvents();
 
-		this.thawHeight();
-		this.releaseScroll();
+			this.thawHeight();
+			this.releaseScroll();
 
-		this.isEventsRendered = false;
+			this.isEventsRendered = false;
+		}
 	},
 
 
@@ -1195,38 +1230,15 @@ var View = FC.View = Model.extend({
 });
 
 
-View.watch('displayingDates', [ 'dateProfile' ], function(deps) {
-	this.requestDateRender(deps.dateProfile);
-}, function() {
-	this.requestDateUnrender();
-});
-
-
 View.watch('initialEvents', [ 'dateProfile' ], function(deps) {
-	return this.calendar.requestEvents(
-		deps.dateProfile.activeRange.start,
-		deps.dateProfile.activeRange.end
-	);
+	return this.fetchInitialEvents(deps.dateProfile);
 });
 
 
 View.watch('bindingEvents', [ 'initialEvents' ], function(deps) {
-	var _this = this;
-
-	this.listenTo(this.calendar, 'eventsReset', function(events) {
-		_this.set('currentEvents', events);
-	});
-
-	// initially set
-	this.set('currentEvents', deps.initialEvents);
-}, function() {
-	this.stopListeningTo(this.calendar, 'eventsReset');
-	this.unset('currentEvents');
-});
-
-
-View.watch('displayingEvents', [ 'displayingDates', 'currentEvents' ], function(deps) {
-	this.requestEventsRender(deps.currentEvents);
+	this.bindEventChanges();
+	this.setEvents(deps.initialEvents);
 }, function() {
-	this.requestEventsUnrender();
+	this.unbindEventChanges();
+	this.unsetEvents();
 });