Skip to content

Commit ac695e5

Browse files
committed
fix(collectionview): refactor to allow plugins to have more access
1 parent 30cd05a commit ac695e5

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/collectionview/index-common.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,11 +462,18 @@ export abstract class CollectionViewBase extends View implements CollectionViewD
462462
// onItemTemplateSelectorPropertyChanged(oldValue, newValue) {
463463
// this.onItemTemplateSelectorChanged(oldValue, newValue);
464464
// }
465+
466+
getItemSourceAtIndex(index: number) {
467+
return (this.items as ItemsSource).getItem(index);
468+
}
469+
getItemArrayAtIndex(index: number) {
470+
return this.items[index];
471+
}
465472
onItemsChanged(oldValue, newValue) {
466473
const getItem = newValue && (newValue as ItemsSource).getItem;
467474
this.isItemsSourceIn = typeof getItem === 'function';
468475
// we override the method to prevent the test on every getItem
469-
this.getItemAtIndex = this.isItemsSourceIn ? (index: number) => (this.items as ItemsSource).getItem(index) : (index: number) => this.items[index];
476+
this.getItemAtIndex = this.isItemsSourceIn ? this.getItemSourceAtIndex.bind(this) : this.getItemArrayAtIndex.bind(this);
470477
if (oldValue instanceof Observable) {
471478
removeWeakEventListener(oldValue, ObservableArray.changeEvent, this.onSourceCollectionChangedInternal, this);
472479
}

0 commit comments

Comments
 (0)