@@ -102,155 +102,153 @@ var RangeSlider = function (_Component) {
102102 helper . selectedSensor . set ( obj , true ) ;
103103 } ;
104104
105- setTimeout ( function ( ) {
106- var defaultValue = _this2 . urlParams !== null ? _this2 . urlParams : nextProps . defaultSelected ;
107- if ( ! _isEqual ( _this2 . props . defaultSelected , nextProps . defaultSelected ) ) {
108- defaultValue = nextProps . defaultSelected ;
109- }
105+ var defaultValue = this . urlParams !== null ? this . urlParams : nextProps . defaultSelected ;
106+ if ( ! _isEqual ( this . props . defaultSelected , nextProps . defaultSelected ) ) {
107+ defaultValue = nextProps . defaultSelected ;
108+ }
110109
111- // check defaultSelected
112- if ( defaultValue && defaultValue . start !== _this2 . state . values . min || defaultValue && defaultValue . end !== _this2 . state . values . max && nextProps . range . start <= defaultValue . start && nextProps . range . end >= defaultValue . end ) {
113- var rem = ( defaultValue . end - defaultValue . start ) % nextProps . stepValue ;
114- if ( rem ) {
115- var values = {
116- min : _this2 . state . values . min ,
117- max : defaultValue . end - rem
118- } ;
119- _this2 . setState ( {
120- values : values
121- } ) ;
122- var obj = {
123- key : nextProps . componentId ,
124- value : {
125- from : values . min ,
126- to : values . max
127- }
128- } ;
129- setTimeout ( function ( ) {
130- if ( _this2 . props . beforeValueChange ) {
131- var nextValue = {
132- start : values . min ,
133- end : values . max
134- } ;
135- _this2 . props . beforeValueChange ( nextValue ) . then ( function ( ) {
136- execQuery ( obj ) ;
137- } ) . catch ( function ( e ) {
138- console . warn ( _this2 . props . componentId + " - beforeValueChange rejected the promise with" , e ) ;
139- } ) ;
140- } else {
110+ // check defaultSelected
111+ if ( defaultValue && defaultValue . start !== this . props . defaultSelected . start || defaultValue && defaultValue . end !== this . props . defaultSelected . end && nextProps . range . start <= defaultValue . start && nextProps . range . end >= defaultValue . end ) {
112+ var rem = ( defaultValue . end - defaultValue . start ) % nextProps . stepValue ;
113+ if ( rem ) {
114+ var values = {
115+ min : this . state . values . min ,
116+ max : defaultValue . end - rem
117+ } ;
118+ this . setState ( {
119+ values : values
120+ } ) ;
121+ var obj = {
122+ key : nextProps . componentId ,
123+ value : {
124+ from : values . min ,
125+ to : values . max
126+ }
127+ } ;
128+ setTimeout ( function ( ) {
129+ if ( _this2 . props . beforeValueChange ) {
130+ var nextValue = {
131+ start : values . min ,
132+ end : values . max
133+ } ;
134+ _this2 . props . beforeValueChange ( nextValue ) . then ( function ( ) {
141135 execQuery ( obj ) ;
142- }
143- } , 1000 ) ;
144- } else {
145- var _values = { } ;
146- _values . min = defaultValue . start ;
147- _values . max = defaultValue . end ;
148- _this2 . setState ( {
149- values : _values ,
150- currentValues : _values
151- } ) ;
152- var _obj = {
153- key : nextProps . componentId ,
154- value : {
155- from : _values . min ,
156- to : _values . max
157- }
158- } ;
159- setTimeout ( function ( ) {
160- if ( _this2 . props . beforeValueChange ) {
161- var nextValue = {
162- start : _values . min ,
163- end : _values . max
164- } ;
165- _this2 . props . beforeValueChange ( nextValue ) . then ( function ( ) {
166- execQuery ( _obj ) ;
167- } ) . catch ( function ( e ) {
168- console . warn ( _this2 . props . componentId + " - beforeValueChange rejected the promise with" , e ) ;
169- } ) ;
170- } else {
171- execQuery ( _obj ) ;
172- }
173- } , 1000 ) ;
174- }
175- }
176- // check range
177- if ( nextProps . range . start !== _this2 . state . startThreshold || nextProps . range . end !== _this2 . state . endThreshold ) {
178- if ( nextProps . range . start <= defaultValue . start && nextProps . range . end >= defaultValue . end ) {
179- _this2 . setState ( {
180- startThreshold : nextProps . range . start ,
181- endThreshold : nextProps . range . end
182- } ) ;
183- } else {
184- var _values2 = {
185- min : _this2 . state . values . min ,
186- max : _this2 . state . values . max
187- } ;
188- if ( _this2 . state . values . min < nextProps . range . start ) {
189- _values2 . min = nextProps . range . start ;
136+ } ) . catch ( function ( e ) {
137+ console . warn ( _this2 . props . componentId + " - beforeValueChange rejected the promise with" , e ) ;
138+ } ) ;
139+ } else {
140+ execQuery ( obj ) ;
190141 }
191- if ( _this2 . state . values . max > nextProps . range . end ) {
192- _values2 . max = nextProps . range . end ;
142+ } , 1000 ) ;
143+ } else {
144+ var _values = { } ;
145+ _values . min = defaultValue . start ;
146+ _values . max = defaultValue . end ;
147+ this . setState ( {
148+ values : _values ,
149+ currentValues : _values
150+ } ) ;
151+ var _obj = {
152+ key : nextProps . componentId ,
153+ value : {
154+ from : _values . min ,
155+ to : _values . max
193156 }
194- _this2 . setState ( {
195- startThreshold : nextProps . range . start ,
196- endThreshold : nextProps . range . end ,
197- values : _values2
198- } ) ;
199- var currentRange = {
200- from : _values2 . min ,
201- to : _values2 . max
202- } ;
203- var _obj2 = {
204- key : _this2 . props . componentId ,
205- value : currentRange
206- } ;
157+ } ;
158+ setTimeout ( function ( ) {
207159 if ( _this2 . props . beforeValueChange ) {
208160 var nextValue = {
209- start : _values2 . min ,
210- end : _values2 . max
161+ start : _values . min ,
162+ end : _values . max
211163 } ;
212164 _this2 . props . beforeValueChange ( nextValue ) . then ( function ( ) {
213- execQuery ( ) ;
165+ execQuery ( _obj ) ;
214166 } ) . catch ( function ( e ) {
215167 console . warn ( _this2 . props . componentId + " - beforeValueChange rejected the promise with" , e ) ;
216168 } ) ;
217169 } else {
218- execQuery ( ) ;
170+ execQuery ( _obj ) ;
219171 }
220- }
221- _this2 . setRangeValue ( ) ;
172+ } , 1000 ) ;
222173 }
223- // drop value if it exceeds the threshold (based on step value)
224- if ( nextProps . stepValue !== _this2 . props . stepValue ) {
225- var _rem = ( defaultValue . end - defaultValue . start ) % nextProps . stepValue ;
226- if ( _rem ) {
227- _this2 . setState ( {
228- values : {
229- min : _this2 . state . values . min ,
230- max : defaultValue . end - _rem
231- }
232- } ) ;
233- var _obj3 = {
234- key : _this2 . props . componentId ,
235- value : {
236- from : _this2 . state . values . min ,
237- to : defaultValue . end - _rem
238- }
174+ }
175+ // check range
176+ if ( nextProps . range . start !== this . state . startThreshold || nextProps . range . end !== this . state . endThreshold ) {
177+ if ( nextProps . range . start <= defaultValue . start && nextProps . range . end >= defaultValue . end ) {
178+ this . setState ( {
179+ startThreshold : nextProps . range . start ,
180+ endThreshold : nextProps . range . end
181+ } ) ;
182+ } else {
183+ var _values2 = {
184+ min : this . state . values . min ,
185+ max : this . state . values . max
186+ } ;
187+ if ( this . state . values . min < nextProps . range . start ) {
188+ _values2 . min = nextProps . range . start ;
189+ }
190+ if ( this . state . values . max > nextProps . range . end ) {
191+ _values2 . max = nextProps . range . end ;
192+ }
193+ this . setState ( {
194+ startThreshold : nextProps . range . start ,
195+ endThreshold : nextProps . range . end ,
196+ values : _values2
197+ } ) ;
198+ var currentRange = {
199+ from : _values2 . min ,
200+ to : _values2 . max
201+ } ;
202+ var _obj2 = {
203+ key : this . props . componentId ,
204+ value : currentRange
205+ } ;
206+ if ( this . props . beforeValueChange ) {
207+ var nextValue = {
208+ start : _values2 . min ,
209+ end : _values2 . max
239210 } ;
240- if ( _this2 . props . onValueChange ) {
241- var _nextValue = {
242- start : _obj3 . value . from ,
243- end : _obj3 . value . to
244- } ;
245- _this2 . props . onValueChange ( _nextValue ) ;
211+ this . props . beforeValueChange ( nextValue ) . then ( function ( ) {
212+ execQuery ( ) ;
213+ } ) . catch ( function ( e ) {
214+ console . warn ( _this2 . props . componentId + " - beforeValueChange rejected the promise with" , e ) ;
215+ } ) ;
216+ } else {
217+ execQuery ( ) ;
218+ }
219+ }
220+ this . setRangeValue ( ) ;
221+ }
222+ // drop value if it exceeds the threshold (based on step value)
223+ if ( nextProps . stepValue !== this . props . stepValue ) {
224+ var _rem = ( defaultValue . end - defaultValue . start ) % nextProps . stepValue ;
225+ if ( _rem ) {
226+ this . setState ( {
227+ values : {
228+ min : this . state . values . min ,
229+ max : defaultValue . end - _rem
246230 }
247- if ( _this2 . props . URLParams ) {
248- helper . URLParams . update ( _this2 . props . componentId , _this2 . setURLParam ( _obj3 . value ) , _this2 . props . URLParams ) ;
231+ } ) ;
232+ var _obj3 = {
233+ key : this . props . componentId ,
234+ value : {
235+ from : this . state . values . min ,
236+ to : defaultValue . end - _rem
249237 }
250- helper . selectedSensor . set ( _obj3 , true ) ;
238+ } ;
239+ if ( this . props . onValueChange ) {
240+ var _nextValue = {
241+ start : _obj3 . value . from ,
242+ end : _obj3 . value . to
243+ } ;
244+ this . props . onValueChange ( _nextValue ) ;
245+ }
246+ if ( this . props . URLParams ) {
247+ helper . URLParams . update ( this . props . componentId , this . setURLParam ( _obj3 . value ) , this . props . URLParams ) ;
251248 }
249+ helper . selectedSensor . set ( _obj3 , true ) ;
252250 }
253- } , 300 ) ;
251+ }
254252 } ;
255253
256254 RangeSlider . prototype . shouldComponentUpdate = function shouldComponentUpdate ( nextProps , nextState ) {
0 commit comments