Skip to content

Commit

Permalink
Merge branch 'master' of github.com:aurelia/ui-virtualization
Browse files Browse the repository at this point in the history
  • Loading branch information
martingust committed Mar 13, 2016
2 parents 91dc00d + ec9494e commit 30f230c
Show file tree
Hide file tree
Showing 28 changed files with 2,601 additions and 1,669 deletions.
6 changes: 2 additions & 4 deletions bower.json
@@ -1,6 +1,6 @@
{
"name": "aurelia-ui-virtualization",
"version": "0.3.1",
"version": "0.3.2",
"description": "A plugin that provides a virtualized repeater and other virtualization services.",
"keywords": [
"aurelia",
Expand All @@ -25,8 +25,6 @@
"aurelia-path": "^1.0.0-beta.1.1.0",
"aurelia-task-queue": "^1.0.0-beta.1.1.1",
"aurelia-templating": "^1.0.0-beta.1.1.1",
"aurelia-templating-resources": "^1.0.0-beta.1.1.1",

"core-js": "zloirock/core-js"
"aurelia-templating-resources": "^1.0.0-beta.1.1.1"
}
}
225 changes: 225 additions & 0 deletions dist/amd/array-virtual-repeat-strategy.js
@@ -0,0 +1,225 @@
define(['exports', 'aurelia-templating-resources/array-repeat-strategy', 'aurelia-templating-resources/repeat-utilities'], function (exports, _aureliaTemplatingResourcesArrayRepeatStrategy, _aureliaTemplatingResourcesRepeatUtilities) {
'use strict';

exports.__esModule = true;

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }

function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var ArrayVirtualRepeatStrategy = (function (_ArrayRepeatStrategy) {
_inherits(ArrayVirtualRepeatStrategy, _ArrayRepeatStrategy);

function ArrayVirtualRepeatStrategy() {
_classCallCheck(this, ArrayVirtualRepeatStrategy);

_ArrayRepeatStrategy.apply(this, arguments);
}

ArrayVirtualRepeatStrategy.prototype.createFirstItem = function createFirstItem(repeat) {
var overrideContext = _aureliaTemplatingResourcesRepeatUtilities.createFullOverrideContext(repeat, repeat.items[0], 0, 1);
var view = repeat.viewFactory.create();
view.bind(overrideContext.bindingContext, overrideContext);
repeat.viewSlot.add(view);
};

ArrayVirtualRepeatStrategy.prototype.instanceChanged = function instanceChanged(repeat, items) {
this._inPlaceProcessItems(repeat, items);
};

ArrayVirtualRepeatStrategy.prototype._standardProcessInstanceChanged = function _standardProcessInstanceChanged(repeat, items) {
for (var i = 1, ii = repeat._viewsLength; i < ii; ++i) {
var overrideContext = _aureliaTemplatingResourcesRepeatUtilities.createFullOverrideContext(repeat, items[i], i, ii);
var view = repeat.viewFactory.create();
view.bind(overrideContext.bindingContext, overrideContext);
repeat.viewSlot.add(view);
}
};

ArrayVirtualRepeatStrategy.prototype._inPlaceProcessItems = function _inPlaceProcessItems(repeat, items) {
var itemsLength = items.length;
var viewsLength = repeat.viewSlot.children.length;
var first = repeat._getIndexOfFirstView();

while (viewsLength > repeat._viewsLength) {
viewsLength--;
repeat.viewSlot.removeAt(viewsLength, true);
}

var local = repeat.local;

for (var i = 0; i < viewsLength; i++) {
var view = repeat.viewSlot.children[i];
var last = i === itemsLength - 1;
var middle = i !== 0 && !last;

if (view.bindingContext[local] === items[i + first] && view.overrideContext.$middle === middle && view.overrideContext.$last === last) {
continue;
}

view.bindingContext[local] = items[i + first];
view.overrideContext.$middle = middle;
view.overrideContext.$last = last;
var j = view.bindings.length;
while (j--) {
_aureliaTemplatingResourcesRepeatUtilities.updateOneTimeBinding(view.bindings[j]);
}
j = view.controllers.length;
while (j--) {
var k = view.controllers[j].boundProperties.length;
while (k--) {
var binding = view.controllers[j].boundProperties[k].binding;
_aureliaTemplatingResourcesRepeatUtilities.updateOneTimeBinding(binding);
}
}
}

for (var i = viewsLength; i < repeat._viewsLength; i++) {
var overrideContext = _aureliaTemplatingResourcesRepeatUtilities.createFullOverrideContext(repeat, items[i], i, itemsLength);
var view = repeat.viewFactory.create();
view.bind(overrideContext.bindingContext, overrideContext);
repeat.viewSlot.add(view);
}
};

ArrayVirtualRepeatStrategy.prototype.instanceMutated = function instanceMutated(repeat, array, splices) {
this._updateViews(repeat, repeat.items, splices);
};

ArrayVirtualRepeatStrategy.prototype._standardProcessInstanceMutated = function _standardProcessInstanceMutated(repeat, array, splices) {
var _this = this;

var removeDelta = 0;
var viewSlot = repeat.viewSlot;
var rmPromises = [];

for (var i = 0, ii = splices.length; i < ii; ++i) {
var splice = splices[i];
var removed = splice.removed;
var viewIndex = this._getViewIndex(repeat, viewSlot, splice.index);
if (viewIndex >= 0) {
for (var j = 0, jj = removed.length; j < jj; ++j) {
var viewOrPromise = viewSlot.removeAt(viewIndex + removeDelta + rmPromises.length, true);

var _length = viewSlot.children.length;
var overrideContext = _aureliaTemplatingResourcesRepeatUtilities.createFullOverrideContext(repeat, repeat.items[_length], _length, repeat.items.length);
var view = repeat.viewFactory.create();
view.bind(overrideContext.bindingContext, overrideContext);
repeat.viewSlot.isAttached = false;
repeat.viewSlot.add(view);
repeat.viewSlot.isAttached = true;

if (viewOrPromise instanceof Promise) {
rmPromises.push(viewOrPromise);
}
}
removeDelta -= splice.addedCount;
}
}

if (rmPromises.length > 0) {
Promise.all(rmPromises).then(function () {
_this._handleAddedSplices(repeat, array, splices);
_this._updateViews(repeat, array, splices);
});
} else {
this._handleAddedSplices(repeat, array, splices);
this._updateViews(repeat, array, splices);
}
};

ArrayVirtualRepeatStrategy.prototype._updateViews = function _updateViews(repeat, items, splices) {
var totalAdded = 0;
var totalRemoved = 0;
repeat.items = items;

for (var i = 0, ii = splices.length; i < ii; ++i) {
var splice = splices[0];
totalAdded += splice.addedCount;
totalRemoved += splice.removed.length;
}

var index = repeat._getIndexOfFirstView() - totalRemoved;

if (index < 0) {
index = 0;
}

var viewSlot = repeat.viewSlot;

for (var i = 0, ii = viewSlot.children.length; i < ii; ++i) {
var view = viewSlot.children[i];
var nextIndex = index + i;
var itemsLength = items.length;
if (nextIndex <= itemsLength - 1) {
view.bindingContext[repeat.local] = items[nextIndex];
_aureliaTemplatingResourcesRepeatUtilities.updateOverrideContext(view.overrideContext, nextIndex, itemsLength);
}
}

var bufferDelta = repeat.itemHeight * totalAdded + repeat.itemHeight * -totalRemoved;

if (repeat._bottomBufferHeight + bufferDelta < 0) {
repeat._topBufferHeight = repeat._topBufferHeight + bufferDelta;
} else {
repeat._bottomBufferHeight = repeat._bottomBufferHeight + bufferDelta;
}

if (repeat._bottomBufferHeight > 0) {
repeat.isLastIndex = false;
}

repeat._adjustBufferHeights();
};

ArrayVirtualRepeatStrategy.prototype._handleAddedSplices = function _handleAddedSplices(repeat, array, splices) {
var spliceIndexLow = undefined;
var arrayLength = array.length;
for (var i = 0, ii = splices.length; i < ii; ++i) {
var splice = splices[i];
var addIndex = splice.index;
var end = splice.index + splice.addedCount;

if (typeof spliceIndexLow === 'undefined' || spliceIndexLow === null || spliceIndexLow > splice.index) {
spliceIndexLow = addIndex;
}

for (; addIndex < end; ++addIndex) {
var overrideContext = _aureliaTemplatingResourcesRepeatUtilities.createFullOverrideContext(repeat, array[addIndex], addIndex, arrayLength);
var view = repeat.viewFactory.create();
view.bind(overrideContext.bindingContext, overrideContext);
repeat.viewSlot.insert(addIndex, view);
}
}

return spliceIndexLow;
};

ArrayVirtualRepeatStrategy.prototype._isIndexInDom = function _isIndexInDom(viewSlot, index) {
if (viewSlot.children.length === 0) {
return false;
}

var indexLow = viewSlot.children[0].overrideContext.$index;
var indexHi = viewSlot.children[viewSlot.children.length - 1].overrideContext.$index;

return index >= indexLow && index <= indexHi;
};

ArrayVirtualRepeatStrategy.prototype._getViewIndex = function _getViewIndex(repeat, viewSlot, index) {
if (viewSlot.children.length === 0) {
return -1;
}
var indexLow = viewSlot.children[0].overrideContext.$index;
var viewIndex = index - indexLow;
if (viewIndex > repeat._viewsLength - 1) {
viewIndex = -1;
}
return viewIndex;
};

return ArrayVirtualRepeatStrategy;
})(_aureliaTemplatingResourcesArrayRepeatStrategy.ArrayRepeatStrategy);

exports.ArrayVirtualRepeatStrategy = ArrayVirtualRepeatStrategy;
});

0 comments on commit 30f230c

Please sign in to comment.