From 3b920b04934a61171316f4e3c02ab644768d2beb Mon Sep 17 00:00:00 2001
From: Simon Egersand <s.egersand@gmail.com>
Date: Sun, 11 Feb 2018 19:11:26 +0100
Subject: [PATCH] Use immutable variables for view modes

---
 DateTime.js |   28 ++++++++++++++++++----------
 1 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/DateTime.js b/DateTime.js
index 6074e16..4481d20 100644
--- a/DateTime.js
+++ b/DateTime.js
@@ -8,6 +8,13 @@
 	CalendarContainer = require('./src/CalendarContainer')
 	;
 
+var viewModes = Object.freeze({
+	YEARS: 'years',
+	MONTHS: 'months',
+	DAYS: 'days',
+	TIME: 'time',
+});
+
 var TYPES = PropTypes;
 var Datetime = createClass({
 	propTypes: {
@@ -25,7 +32,7 @@
 		// timeFormat: TYPES.string | TYPES.bool,
 		inputProps: TYPES.object,
 		timeConstraints: TYPES.object,
-		viewMode: TYPES.oneOf(['years', 'months', 'days', 'time']),
+		viewMode: TYPES.oneOf([viewModes.YEARS, viewModes.MONTHS, viewModes.DAYS, viewModes.TIME]),
 		isValidDate: TYPES.func,
 		open: TYPES.bool,
 		strictParsing: TYPES.bool,
@@ -39,7 +46,8 @@
 		if ( state.open === undefined )
 			state.open = !this.props.input;
 
-		state.currentView = this.props.dateFormat ? (this.props.viewMode || state.updateOn || 'days') : 'time';
+		state.currentView = this.props.dateFormat ?
+			(this.props.viewMode || state.updateOn || viewModes.DAYS) : viewModes.TIME;
 
 		return state;
 	},
@@ -93,14 +101,14 @@
 
 	getUpdateOn: function( formats ) {
 		if ( formats.date.match(/[lLD]/) ) {
-			return 'days';
+			return viewModes.DAYS;
 		} else if ( formats.date.indexOf('M') !== -1 ) {
-			return 'months';
+			return viewModes.MONTHS;
 		} else if ( formats.date.indexOf('Y') !== -1 ) {
-			return 'years';
+			return viewModes.YEARS;
 		}
 
-		return 'days';
+		return viewModes.DAYS;
 	},
 
 	getFormats: function( props ) {
@@ -114,7 +122,7 @@
 		if ( formats.date === true ) {
 			formats.date = locale.longDateFormat('L');
 		}
-		else if ( this.getUpdateOn(formats) !== 'days' ) {
+		else if ( this.getUpdateOn(formats) !== viewModes.DAYS ) {
 			formats.time = '';
 		}
 
@@ -143,7 +151,7 @@
 		if ( updatedState.open === undefined ) {
 			if ( typeof nextProps.open !== 'undefined' ) {
 				updatedState.open = nextProps.open;
-			} else if ( this.props.closeOnSelect && this.state.currentView !== 'time' ) {
+			} else if ( this.props.closeOnSelect && this.state.currentView !== viewModes.TIME ) {
 				updatedState.open = false;
 			} else {
 				updatedState.open = this.state.open;
@@ -232,8 +240,8 @@
 	setDate: function( type ) {
 		var me = this,
 			nextViews = {
-				month: 'days',
-				year: 'months'
+				month: viewModes.DAYS,
+				year: viewModes.MONTHS,
 			}
 		;
 		return function( e ) {

--
Gitblit v1.9.3