@@ -22,11 +22,11 @@ angular.module('ui.scroll', [])
2222 this . viewport = element ;
2323 this . scope = scope ;
2424
25- angular . forEach ( element . children ( ) , ( child => {
25+ angular . forEach ( element . children ( ) , child => {
2626 if ( child . tagName . toLowerCase ( ) === 'tbody' ) {
2727 this . viewport = angular . element ( child ) ;
2828 }
29- } ) ) ;
29+ } ) ;
3030
3131 return this ;
3232 }
@@ -84,13 +84,15 @@ angular.module('ui.scroll', [])
8484 const elementRoutines = new ElementRoutines ( $injector , $q ) ;
8585 const buffer = new ScrollBuffer ( elementRoutines , bufferSize ) ;
8686 const viewport = new Viewport ( elementRoutines , buffer , element , viewportController , $rootScope , padding ) ;
87- const adapter = new Adapter ( viewport , buffer , adjustBuffer , reload , $attr , $parse , $scope ) ;
87+ const adapter = new Adapter ( $scope , $parse , $attr , viewport , buffer , doAdjust , reload ) ;
8888
8989 if ( viewportController ) {
9090 viewportController . adapter = adapter ;
9191 }
9292
93- const isDatasourceValid = ( ) => angular . isObject ( datasource ) && angular . isFunction ( datasource . get ) ;
93+ const isDatasourceValid = ( ) =>
94+ Object . prototype . toString . call ( datasource ) === '[object Object]' && typeof datasource . get === 'function' ;
95+
9496 datasource = $parse ( datasourceName ) ( $scope ) ; // try to get datasource on scope
9597 if ( ! isDatasourceValid ( ) ) {
9698 datasource = $injector . get ( datasourceName ) ; // try to inject datasource as service
@@ -101,12 +103,10 @@ angular.module('ui.scroll', [])
101103
102104 let onRenderHandlers = [ ] ;
103105 function onRenderHandlersRunner ( ) {
104- if ( onRenderHandlers . length ) {
105- angular . forEach ( onRenderHandlers , ( handler ) => handler ( ) ) ;
106- onRenderHandlers = [ ] ;
107- }
106+ onRenderHandlers . forEach ( handler => handler ( ) ) ;
107+ onRenderHandlers = [ ] ;
108108 }
109- function preDefineIndexProperty ( datasource , propName ) {
109+ function persistDatasourceIndex ( datasource , propName , doNotDelete ) {
110110 let getter ;
111111 // need to postpone min/maxIndexUser processing if the view is empty
112112 if ( datasource . hasOwnProperty ( propName ) && ! buffer . length ) {
@@ -116,13 +116,13 @@ angular.module('ui.scroll', [])
116116 }
117117 }
118118
119- function defineIndexProperty ( datasource , propName , propUserName ) {
119+ function defineDatasourceIndex ( datasource , propName , propUserName ) {
120120 const descriptor = Object . getOwnPropertyDescriptor ( datasource , propName ) ;
121121 if ( descriptor && ( descriptor . set || descriptor . get ) ) {
122122 return ;
123123 }
124124 let getter ;
125- preDefineIndexProperty ( datasource , propName ) ;
125+ persistDatasourceIndex ( datasource , propName ) ;
126126 Object . defineProperty ( datasource , propName , {
127127 set : ( value ) => {
128128 getter = value ;
@@ -137,8 +137,8 @@ angular.module('ui.scroll', [])
137137 } ) ;
138138 }
139139
140- defineIndexProperty ( datasource , 'minIndex' , 'minIndexUser' ) ;
141- defineIndexProperty ( datasource , 'maxIndex' , 'maxIndexUser' ) ;
140+ defineDatasourceIndex ( datasource , 'minIndex' , 'minIndexUser' ) ;
141+ defineDatasourceIndex ( datasource , 'maxIndex' , 'maxIndexUser' ) ;
142142
143143 const fetchNext = ( datasource . get . length !== 2 ) ?
144144 ( success ) => datasource . get ( buffer . next , bufferSize , success ) :
@@ -160,7 +160,7 @@ angular.module('ui.scroll', [])
160160 } , success ) ;
161161 } ;
162162
163- const run = ( ) => {
163+ const initialize = ( ) => {
164164 let tryCount = 0 ;
165165 if ( ! viewport . applyContainerStyle ( ) ) {
166166 const timer = $interval ( ( ) => {
@@ -203,7 +203,7 @@ angular.module('ui.scroll', [])
203203
204204 viewport . bind ( 'mousewheel' , wheelHandler ) ;
205205
206- run ( ) ;
206+ initialize ( ) ;
207207
208208 /* Private function definitions */
209209
@@ -228,7 +228,7 @@ angular.module('ui.scroll', [])
228228 startIndex = arguments [ 0 ] ;
229229 }
230230 buffer . reset ( startIndex ) ;
231- adjustBuffer ( ) ;
231+ doAdjust ( ) ;
232232 }
233233
234234 function isElementVisible ( wrapper ) {
@@ -238,13 +238,13 @@ angular.module('ui.scroll', [])
238238 function visibilityWatcher ( wrapper ) {
239239 if ( isElementVisible ( wrapper ) ) {
240240 buffer . forEach ( ( item ) => {
241- if ( angular . isFunction ( item . unregisterVisibilityWatcher ) ) {
241+ if ( typeof item . unregisterVisibilityWatcher === 'function' ) {
242242 item . unregisterVisibilityWatcher ( ) ;
243243 delete item . unregisterVisibilityWatcher ;
244244 }
245245 } ) ;
246246 if ( ! pending . length ) {
247- $timeout ( ( ) => adjustBuffer ( ) ) ;
247+ $timeout ( ( ) => doAdjust ( ) ) ;
248248 }
249249 }
250250 }
@@ -327,11 +327,11 @@ angular.module('ui.scroll', [])
327327 }
328328
329329 function updatePaddings ( rid , updates ) {
330- // schedule another adjustBuffer after animation completion
330+ // schedule another doAdjust after animation completion
331331 if ( updates . animated . length ) {
332332 $q . all ( updates . animated ) . then ( ( ) => {
333333 viewport . adjustPaddings ( ) ;
334- adjustBuffer ( rid ) ;
334+ doAdjust ( rid ) ;
335335 } ) ;
336336 } else {
337337 viewport . adjustPaddings ( ) ;
@@ -371,7 +371,7 @@ angular.module('ui.scroll', [])
371371 return updates ;
372372 }
373373
374- function adjustBuffer ( rid ) {
374+ function doAdjust ( rid ) {
375375 if ( ! rid ) { // dismiss pending requests
376376 pending = [ ] ;
377377 rid = ++ ridActual ;
@@ -391,7 +391,7 @@ angular.module('ui.scroll', [])
391391 }
392392 }
393393
394- function adjustBufferAfterFetch ( rid ) {
394+ function doAdjustAfterFetch ( rid ) {
395395 const updates = processUpdates ( ) ;
396396
397397 viewport . onAfterPrepend ( updates ) ;
@@ -417,7 +417,7 @@ angular.module('ui.scroll', [])
417417 function fetch ( rid ) {
418418 if ( pending [ 0 ] ) { // scrolling down
419419 if ( buffer . length && ! viewport . shouldLoadBottom ( ) ) {
420- adjustBufferAfterFetch ( rid ) ;
420+ doAdjustAfterFetch ( rid ) ;
421421 } else {
422422 fetchNext ( ( result ) => {
423423 if ( isInvalid ( rid ) ) {
@@ -433,12 +433,12 @@ angular.module('ui.scroll', [])
433433 buffer . append ( result ) ;
434434 }
435435
436- adjustBufferAfterFetch ( rid ) ;
436+ doAdjustAfterFetch ( rid ) ;
437437 } ) ;
438438 }
439439 } else { // scrolling up
440440 if ( buffer . length && ! viewport . shouldLoadTop ( ) ) {
441- adjustBufferAfterFetch ( rid ) ;
441+ doAdjustAfterFetch ( rid ) ;
442442 } else {
443443 fetchPrevious ( ( result ) => {
444444 if ( isInvalid ( rid ) ) {
@@ -457,7 +457,7 @@ angular.module('ui.scroll', [])
457457 buffer . prepend ( result ) ;
458458 }
459459
460- adjustBufferAfterFetch ( rid ) ;
460+ doAdjustAfterFetch ( rid ) ;
461461 } ) ;
462462 }
463463 }
0 commit comments