Skip to content
Permalink
Browse files

fix(interfaces): properly handle first/last element gets

  • Loading branch information...
bigopon committed Feb 23, 2019
1 parent 5aee525 commit eb6e4a353456e6c6468bb66ee146738de90fe0d1
Showing with 30 additions and 14 deletions.
  1. +1 −1 src/array-virtual-repeat-strategy.ts
  2. +22 −3 src/interfaces.ts
  3. +6 −9 src/template-strategy-default.ts
  4. +1 −1 src/virtual-repeat.ts
@@ -294,7 +294,7 @@ export class ArrayVirtualRepeatStrategy extends ArrayRepeatStrategy implements I
let addIndex = splice.index;
let end = splice.index + splice.addedCount;
for (; addIndex < end; ++addIndex) {
let hasDistanceToBottomViewPort = getElementDistanceToBottomViewPort(repeat.templateStrategy.getLastElement(repeat.bottomBufferEl)) > 0;
let hasDistanceToBottomViewPort = getElementDistanceToBottomViewPort(repeat.templateStrategy.getLastElement(repeat.topBufferEl, repeat.bottomBufferEl)) > 0;
if (repeat.viewCount() === 0
|| (!this._isIndexBeforeViewSlot(repeat, viewSlot, addIndex)
&& !this._isIndexAfterViewSlot(repeat, viewSlot, addIndex)
@@ -80,18 +80,37 @@ export interface IVirtualRepeatStrategy extends RepeatStrategy {
*/
export interface ITemplateStrategy {
/**
* Determine the scroll container of a [repeat] based on its anchor (`element` is a comment node)
* Determine the scroll container of a [virtual-repeat] based on its anchor (`element` is a comment node)
*/
getScrollContainer(element: Element): HTMLElement;
/**
* Move root element of a view to first position in the list, after top buffer
* Note: [virtual-repeat] only supports single root node repeat
*/
moveViewFirst(view: View, topBuffer: Element): void;
/**
* Move root element of a view to last position in the list, before bottomBuffer
* Note: [virtual-repeat] only supports single root node repeat
*/
moveViewLast(view: View, bottomBuffer: Element): void;
/**
* Create top and bottom buffer elements for an anchor (`element` is a comment node)
*/
createBuffers(element: Element): [HTMLElement, HTMLElement];
/**
* Clean up buffers of a [virtual-repeat]
*/
removeBuffers(element: Element, topBuffer: Element, bottomBuffer: Element): void;
getFirstElement(topBuffer: Element): Element;
getLastElement(bottomBuffer: Element): Element;
/**
* Get the first element(or view) between top buffer and bottom buffer
* Note: [virtual-repeat] only supports single root node repeat
*/
getFirstElement(topBufer: Element, topBuffer: Element): Element;
/**
* Get the last element(or view) between top buffer and bottom buffer
* Note: [virtual-repeat] only supports single root node repeat
*/
getLastElement(topBuffer: Element, bottomBuffer: Element): Element;
/**
* Distance of top buffer to the top of its offseting parent
*/
@@ -32,17 +32,14 @@ export class DefaultTemplateStrategy implements ITemplateStrategy {
parent.removeChild(bottomBuffer);
}

removeBufferElements(element: Element, topBuffer: Element, bottomBuffer: Element): void {
element.parentNode.removeChild(topBuffer);
element.parentNode.removeChild(bottomBuffer);
getFirstElement(topBuffer: Element, bottomBuffer: Element): Element {
const firstEl = topBuffer.nextElementSibling;
return firstEl === bottomBuffer ? null : firstEl;
}

getFirstElement(topBuffer: Element): Element {
return topBuffer.nextElementSibling;
}

getLastElement(bottomBuffer: Element): Element {
return bottomBuffer.previousElementSibling;
getLastElement(topBuffer: Element, bottomBuffer: Element): Element {
const lastEl = bottomBuffer.previousElementSibling;
return lastEl === topBuffer ? null : lastEl;
}

getTopBufferDistance(topBuffer: Element): number {
@@ -313,7 +313,7 @@ export class VirtualRepeat extends AbstractRepeater {
// When dealing with tables, there can be gaps between elements, causing distances to be messed up. Might need to handle this case here.
this.topBufferDistance = templateStrategy.getTopBufferDistance(topBufferEl);
this.distanceToTop = DomHelper
.getElementDistanceToTopOfDocument(templateStrategy.getFirstElement(topBufferEl));
.getElementDistanceToTopOfDocument(templateStrategy.getFirstElement(topBufferEl, bottomBufferEl));

if (DomHelper.hasOverflowScroll(scrollContainer)) {
this._fixedHeightContainer = true;

0 comments on commit eb6e4a3

Please sign in to comment.
You can’t perform that action at this time.