@@ -43,7 +43,7 @@ export interface RxListManager<T> {
43
43
44
44
export function createListTemplateManager <
45
45
T ,
46
- C extends RxListViewContext < T >
46
+ C extends RxListViewContext < T > ,
47
47
> ( config : {
48
48
renderSettings : RxRenderSettings ;
49
49
templateSettings : RxListTemplateSettings < T , C , RxListViewComputedContext > & {
@@ -92,7 +92,7 @@ export function createListTemplateManager<
92
92
strategyHandling$ . next ( nextConfig ) ;
93
93
} ,
94
94
render (
95
- values$ : Observable < NgIterable < T > >
95
+ values$ : Observable < NgIterable < T > > ,
96
96
) : Observable < NgIterable < T > | null > {
97
97
return values$ . pipe ( render ( ) ) ;
98
98
} ,
@@ -105,7 +105,7 @@ export function createListTemplateManager<
105
105
partiallyFinished = false ;
106
106
errorHandler . handleError ( err ) ;
107
107
return of ( null ) ;
108
- } )
108
+ } ) ,
109
109
) ;
110
110
}
111
111
@@ -116,24 +116,30 @@ export function createListTemplateManager<
116
116
strategyHandling$ . strategy$ . pipe ( distinctUntilChanged ( ) ) ,
117
117
] ) . pipe (
118
118
map ( ( [ iterable , strategy ] ) => {
119
- const differ = getDiffer ( iterable ) ;
120
- let changes : IterableChanges < T > ;
121
- if ( differ ) {
122
- if ( partiallyFinished ) {
123
- const currentIterable = [ ] ;
124
- for ( let i = 0 , ilen = viewContainerRef . length ; i < ilen ; i ++ ) {
125
- const viewRef = < EmbeddedViewRef < C > > viewContainerRef . get ( i ) ;
126
- currentIterable [ i ] = viewRef . context . $implicit ;
119
+ try {
120
+ const differ = getDiffer ( iterable ) ;
121
+ let changes : IterableChanges < T > ;
122
+ if ( differ ) {
123
+ if ( partiallyFinished ) {
124
+ const currentIterable = [ ] ;
125
+ for ( let i = 0 , ilen = viewContainerRef . length ; i < ilen ; i ++ ) {
126
+ const viewRef = < EmbeddedViewRef < C > > viewContainerRef . get ( i ) ;
127
+ currentIterable [ i ] = viewRef . context . $implicit ;
128
+ }
129
+ differ . diff ( currentIterable ) ;
127
130
}
128
- differ . diff ( currentIterable ) ;
131
+ changes = differ . diff ( iterable ) ;
129
132
}
130
- changes = differ . diff ( iterable ) ;
133
+ return {
134
+ changes,
135
+ iterable,
136
+ strategy,
137
+ } ;
138
+ } catch {
139
+ throw new Error (
140
+ `Error trying to diff '${ iterable } '. Only arrays and iterables are allowed` ,
141
+ ) ;
131
142
}
132
- return {
133
- changes,
134
- iterable,
135
- strategy,
136
- } ;
137
143
} ) ,
138
144
// Cancel old renders
139
145
switchMap ( ( { changes, iterable, strategy } ) => {
@@ -149,25 +155,25 @@ export function createListTemplateManager<
149
155
const applyChanges$ = getObservablesFromChangesArray (
150
156
changesArr ,
151
157
strategy ,
152
- items . length
158
+ items . length ,
153
159
) ;
154
160
partiallyFinished = true ;
155
161
notifyParent = insertedOrRemoved && parent ;
156
162
return combineLatest (
157
- applyChanges$ . length > 0 ? applyChanges$ : [ of ( null ) ]
163
+ applyChanges$ . length > 0 ? applyChanges$ : [ of ( null ) ] ,
158
164
) . pipe (
159
165
tap ( ( ) => ( partiallyFinished = false ) ) ,
160
166
notifyAllParentsIfNeeded (
161
167
injectingViewCdRef ,
162
168
strategy ,
163
169
( ) => notifyParent ,
164
- ngZone
170
+ ngZone ,
165
171
) ,
166
172
handleError ( ) ,
167
- map ( ( ) => iterable )
173
+ map ( ( ) => iterable ) ,
168
174
) ;
169
175
} ) ,
170
- handleError ( )
176
+ handleError ( ) ,
171
177
) ;
172
178
}
173
179
@@ -185,7 +191,7 @@ export function createListTemplateManager<
185
191
function getObservablesFromChangesArray (
186
192
changes : RxListTemplateChange < T > [ ] ,
187
193
strategy : RxStrategyCredentials ,
188
- count : number
194
+ count : number ,
189
195
) : Observable < RxListTemplateChangeType > [ ] {
190
196
return changes . length > 0
191
197
? changes . map ( ( change ) => {
@@ -203,7 +209,7 @@ export function createListTemplateManager<
203
209
payload [ 2 ] ,
204
210
payload [ 0 ] ,
205
211
payload [ 1 ] ,
206
- count
212
+ count ,
207
213
) ;
208
214
break ;
209
215
case RxListTemplateChangeType . remove :
@@ -216,12 +222,12 @@ export function createListTemplateManager<
216
222
listViewHandler . updateUnchangedContext (
217
223
payload [ 0 ] ,
218
224
7338
payload [ 1 ] ,
219
- count
225
+ count ,
220
226
) ;
221
227
break ;
222
228
}
223
229
} ,
224
- { ngZone }
230
+ { ngZone } ,
225
231
) ;
226
232
} )
227
233
: [ of ( null ) ] ;
0 commit comments