Created
October 18, 2019 18:13
-
-
Save okhobb/6873e751f4e9959690aece852e502e3f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private _applyChanges(changes: IterableChanges<T>) { | |
let singleAddIndex: number|undefined = undefined; | |
let singleRemoveIndex: number|undefined = undefined; | |
let hasMultipleMutations: boolean = false; | |
let singleMutatedItem: T|undefined = undefined; | |
changes.forEachOperation((item: IterableChangeRecord<any>, adjustedPreviousIndex: number | null, currentIndex: number | null) => { | |
if (! hasMultipleMutations) { | |
if (adjustedPreviousIndex === null && currentIndex !== null) { | |
if (! singleAddIndex) { | |
singleAddIndex = currentIndex; | |
singleMutatedItem = item.item; | |
} else { | |
hasMultipleMutations = true; | |
} | |
} | |
if (adjustedPreviousIndex !== null && currentIndex === null) { | |
if (! singleRemoveIndex) { | |
singleRemoveIndex = adjustedPreviousIndex; | |
} else { | |
hasMultipleMutations = true; | |
} | |
} | |
} | |
}); | |
if (! hasMultipleMutations && singleAddIndex !== undefined && singleRemoveIndex !== undefined && singleAddIndex === singleRemoveIndex) { | |
const viewRef = <EmbeddedViewRef<PpNgForOfContext<T>>>this._viewContainer.get(singleAddIndex); | |
viewRef.context.$implicit = singleMutatedItem; | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment