dispose-view-repeater-strategy-D_JReLI1.mjs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { a as _ViewRepeaterOperation } from './recycle-view-repeater-strategy-DoWdPqVw.mjs';
  2. /**
  3. * A repeater that destroys views when they are removed from a
  4. * {@link ViewContainerRef}. When new items are inserted into the container,
  5. * the repeater will always construct a new embedded view for each item.
  6. *
  7. * @template T The type for the embedded view's $implicit property.
  8. * @template R The type for the item in each IterableDiffer change record.
  9. * @template C The type for the context passed to each embedded view.
  10. */
  11. class _DisposeViewRepeaterStrategy {
  12. applyChanges(changes, viewContainerRef, itemContextFactory, itemValueResolver, itemViewChanged) {
  13. changes.forEachOperation((record, adjustedPreviousIndex, currentIndex) => {
  14. let view;
  15. let operation;
  16. if (record.previousIndex == null) {
  17. const insertContext = itemContextFactory(record, adjustedPreviousIndex, currentIndex);
  18. view = viewContainerRef.createEmbeddedView(insertContext.templateRef, insertContext.context, insertContext.index);
  19. operation = _ViewRepeaterOperation.INSERTED;
  20. }
  21. else if (currentIndex == null) {
  22. viewContainerRef.remove(adjustedPreviousIndex);
  23. operation = _ViewRepeaterOperation.REMOVED;
  24. }
  25. else {
  26. view = viewContainerRef.get(adjustedPreviousIndex);
  27. viewContainerRef.move(view, currentIndex);
  28. operation = _ViewRepeaterOperation.MOVED;
  29. }
  30. if (itemViewChanged) {
  31. itemViewChanged({
  32. context: view?.context,
  33. operation,
  34. record,
  35. });
  36. }
  37. });
  38. }
  39. detach() { }
  40. }
  41. export { _DisposeViewRepeaterStrategy as _ };
  42. //# sourceMappingURL=dispose-view-repeater-strategy-D_JReLI1.mjs.map