@@ -121,38 +121,38 @@ class Adapter {
121
121
this . viewport . clipBottom ( ) ;
122
122
}
123
123
124
- applyUpdates ( arg1 , arg2 ) {
124
+ applyUpdates ( arg1 , arg2 , arg3 ) {
125
125
if ( typeof arg1 === 'function' ) {
126
- this . applyUpdatesFunc ( arg1 ) ;
126
+ this . applyUpdatesFunc ( arg1 , arg2 ) ;
127
127
} else {
128
- this . applyUpdatesIndex ( arg1 , arg2 ) ;
128
+ this . applyUpdatesIndex ( arg1 , arg2 , arg3 ) ;
129
129
}
130
130
this . doAdjust ( ) ;
131
131
}
132
132
133
- applyUpdatesFunc ( cb ) {
133
+ applyUpdatesFunc ( cb , options ) {
134
134
this . buffer . slice ( 0 ) . forEach ( ( wrapper ) => {
135
135
// we need to do it on the buffer clone, because buffer content
136
136
// 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 ) ;
138
138
} ) ;
139
139
}
140
140
141
- applyUpdatesIndex ( index , newItems ) {
141
+ applyUpdatesIndex ( index , newItems , options = { } ) {
142
142
if ( index % 1 !== 0 ) {
143
143
throw new Error ( 'applyUpdates - ' + index + ' is not a valid index (should be an integer)' ) ;
144
144
}
145
145
const _index = index - this . buffer . first ;
146
146
147
147
// apply updates only within buffer
148
148
if ( _index >= 0 && _index < this . buffer . length ) {
149
- this . applyUpdate ( this . buffer [ _index ] , newItems ) ;
149
+ this . applyUpdate ( this . buffer [ _index ] , newItems , options ) ;
150
150
}
151
151
// out-of-buffer case: deletion may affect Paddings
152
152
else if ( index >= this . buffer . getAbsMinIndex ( ) && index <= this . buffer . getAbsMaxIndex ( ) ) {
153
153
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 ( ) ) {
156
156
this . buffer . incrementMinIndex ( ) ;
157
157
}
158
158
else {
@@ -162,14 +162,14 @@ class Adapter {
162
162
}
163
163
}
164
164
165
- applyUpdate ( wrapper , newItems ) {
165
+ applyUpdate ( wrapper , newItems , options = { } ) {
166
166
if ( ! angular . isArray ( newItems ) ) {
167
167
return ;
168
168
}
169
169
let position = this . buffer . indexOf ( wrapper ) ;
170
170
if ( ! newItems . reverse ( ) . some ( newItem => newItem === wrapper . item ) ) {
171
171
wrapper . op = 'remove' ;
172
- if ( position === 0 && ! newItems . length ) {
172
+ if ( ! options . immutableTop && position === 0 && ! newItems . length ) {
173
173
wrapper . _op = 'isTop' ; // to catch "first" edge case on remove
174
174
}
175
175
}
@@ -178,7 +178,7 @@ class Adapter {
178
178
position -- ;
179
179
} else {
180
180
// 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 ) ;
182
182
}
183
183
} ) ;
184
184
}
0 commit comments