@@ -121,38 +121,38 @@ class Adapter {
121121 this . viewport . clipBottom ( ) ;
122122 }
123123
124- applyUpdates ( arg1 , arg2 ) {
124+ applyUpdates ( arg1 , arg2 , arg3 ) {
125125 if ( typeof arg1 === 'function' ) {
126- this . applyUpdatesFunc ( arg1 ) ;
126+ this . applyUpdatesFunc ( arg1 , arg2 ) ;
127127 } else {
128- this . applyUpdatesIndex ( arg1 , arg2 ) ;
128+ this . applyUpdatesIndex ( arg1 , arg2 , arg3 ) ;
129129 }
130130 this . doAdjust ( ) ;
131131 }
132132
133- applyUpdatesFunc ( cb ) {
133+ applyUpdatesFunc ( cb , options ) {
134134 this . buffer . slice ( 0 ) . forEach ( ( wrapper ) => {
135135 // we need to do it on the buffer clone, because buffer content
136136 // may change as we iterate through
137- this . applyUpdate ( wrapper , cb ( wrapper . item , wrapper . scope , wrapper . element ) ) ;
137+ this . applyUpdate ( wrapper , cb ( wrapper . item , wrapper . scope , wrapper . element ) , options ) ;
138138 } ) ;
139139 }
140140
141- applyUpdatesIndex ( index , newItems ) {
141+ applyUpdatesIndex ( index , newItems , options = { } ) {
142142 if ( index % 1 !== 0 ) {
143143 throw new Error ( 'applyUpdates - ' + index + ' is not a valid index (should be an integer)' ) ;
144144 }
145145 const _index = index - this . buffer . first ;
146146
147147 // apply updates only within buffer
148148 if ( _index >= 0 && _index < this . buffer . length ) {
149- this . applyUpdate ( this . buffer [ _index ] , newItems ) ;
149+ this . applyUpdate ( this . buffer [ _index ] , newItems , options ) ;
150150 }
151151 // out-of-buffer case: deletion may affect Paddings
152152 else if ( index >= this . buffer . getAbsMinIndex ( ) && index <= this . buffer . getAbsMaxIndex ( ) ) {
153153 if ( angular . isArray ( newItems ) && ! newItems . length ) {
154- this . viewport . removeCacheItem ( index , index === this . buffer . minIndex ) ;
155- if ( index === this . buffer . getAbsMinIndex ( ) ) {
154+ this . viewport . removeCacheItem ( index , ! options . immutableTop && index === this . buffer . minIndex ) ;
155+ if ( ! options . immutableTop && index === this . buffer . getAbsMinIndex ( ) ) {
156156 this . buffer . incrementMinIndex ( ) ;
157157 }
158158 else {
@@ -162,14 +162,14 @@ class Adapter {
162162 }
163163 }
164164
165- applyUpdate ( wrapper , newItems ) {
165+ applyUpdate ( wrapper , newItems , options = { } ) {
166166 if ( ! angular . isArray ( newItems ) ) {
167167 return ;
168168 }
169169 let position = this . buffer . indexOf ( wrapper ) ;
170170 if ( ! newItems . reverse ( ) . some ( newItem => newItem === wrapper . item ) ) {
171171 wrapper . op = 'remove' ;
172- if ( position === 0 && ! newItems . length ) {
172+ if ( ! options . immutableTop && position === 0 && ! newItems . length ) {
173173 wrapper . _op = 'isTop' ; // to catch "first" edge case on remove
174174 }
175175 }
@@ -178,7 +178,7 @@ class Adapter {
178178 position -- ;
179179 } else {
180180 // 3 parameter (isTop) is to catch "first" edge case on insert
181- this . buffer . insert ( position + 1 , newItem , position === - 1 ) ;
181+ this . buffer . insert ( position + 1 , newItem , ! options . immutableTop && position === - 1 ) ;
182182 }
183183 } ) ;
184184 }
0 commit comments