Skip to content

Commit ab4d2d9

Browse files
committed
improved latching render all
1 parent 0eb909a commit ab4d2d9

File tree

5 files changed

+83
-63
lines changed

5 files changed

+83
-63
lines changed

dist/angular-vs-repeat.js

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ function _slicedToArray(arr, i) { if (Array.isArray(arr)) { return arr; } else i
153153
throw new Error('angular-vs-repeat: no ng-repeat directive on a child element');
154154
}
155155

156-
function printDeprecationWarning(message) {
157-
console.warn("vs-repeat deprecation: ".concat(message));
156+
function printDeprecationWarning($element, message) {
157+
console.warn("vs-repeat deprecation: ".concat(message), $element[0]);
158158
}
159159

160-
function attrDeprecated(attrname) {
161-
printDeprecationWarning("".concat(attrname, " attribute is deprecated. Pass the options object to vs-repeat attribute instead <link>."));
160+
function attrDeprecated(attrname, $element) {
161+
printDeprecationWarning($element, "".concat(attrname, " attribute is deprecated. Pass the options object to vs-repeat attribute instead https://github.com/kamilkp/angular-vs-repeat#options"));
162162
}
163163

164164
var defaultOptions = {
@@ -191,7 +191,7 @@ function _slicedToArray(arr, i) { if (Array.isArray(arr)) { return arr; } else i
191191

192192
['vsSize', 'vsScrollParent', 'vsSizeProperty', 'vsHorizontal', 'vsOffsetBefore', 'vsOffsetAfter', 'vsScrolledToEndOffset', 'vsScrolledToBeginningOffset', 'vsExcess', 'vsScrollMargin'].forEach(function (attrname) {
193193
if (attrname in compileAttrs) {
194-
attrDeprecated(attrname);
194+
attrDeprecated(attrname, compileElement);
195195
}
196196
});
197197

@@ -381,7 +381,7 @@ function _slicedToArray(arr, i) { if (Array.isArray(arr)) { return arr; } else i
381381
autosizingRequired = false;
382382

383383
if ($scope.$root && !$scope.$root.$$phase) {
384-
$scope.$apply();
384+
$scope.$digest();
385385
}
386386
}
387387
} else {
@@ -416,11 +416,6 @@ function _slicedToArray(arr, i) { if (Array.isArray(arr)) { return arr; } else i
416416
function scrollHandler() {
417417
if (updateInnerCollection()) {
418418
$scope.$digest();
419-
var expectedSize = $scope.vsRepeat.sizesCumulative[originalLength];
420-
421-
if (expectedSize !== repeatContainer[0][scrollSize]) {
422-
console.warn('vsRepeat: size mismatch. Expected size ' + expectedSize + 'px whereas actual size is ' + repeatContainer[0][scrollSize] + 'px. Fix vsSize on element:', $element[0]);
423-
}
424419
}
425420
}
426421

@@ -432,7 +427,7 @@ function _slicedToArray(arr, i) { if (Array.isArray(arr)) { return arr; } else i
432427
getFromMeasured();
433428

434429
if ($scope.$root && !$scope.$root.$$phase) {
435-
$scope.$apply();
430+
$scope.$digest();
436431
}
437432
}
438433

@@ -455,24 +450,30 @@ function _slicedToArray(arr, i) { if (Array.isArray(arr)) { return arr; } else i
455450
var _prevStartIndex, _prevEndIndex, _minStartIndex, _maxEndIndex;
456451

457452
$scope.$on('vsRenderAll', function () {
458-
//e , quantum) {
459-
if (options.latch) {
460-
setTimeout(function () {
461-
// var __endIndex = Math.min($scope.vsRepeat.endIndex + (quantum || 1), originalLength);
462-
var __endIndex = originalLength;
463-
_maxEndIndex = Math.max(__endIndex, _maxEndIndex);
464-
$scope.vsRepeat.endIndex = options.latch ? _maxEndIndex : __endIndex;
465-
$scope[collectionName] = originalCollection.slice($scope.vsRepeat.startIndex, $scope.vsRepeat.endIndex);
466-
_prevEndIndex = $scope.vsRepeat.endIndex;
467-
$scope.$$postDigest(function () {
468-
$beforeContent.css(getLayoutProp(), 0);
469-
$afterContent.css(getLayoutProp(), 0);
470-
});
471-
$scope.$apply(function () {
472-
$scope.$emit('vsRenderAllDone');
473-
});
474-
});
453+
if (!options.latch) {
454+
return;
455+
}
456+
457+
if ($scope.vsRepeat.endIndex === originalLength) {
458+
$scope.$emit('vsRenderAllDone');
459+
return;
475460
}
461+
462+
setTimeout(function () {
463+
// var __endIndex = Math.min($scope.vsRepeat.endIndex + (quantum || 1), originalLength);
464+
var __endIndex = originalLength;
465+
_maxEndIndex = Math.max(__endIndex, _maxEndIndex);
466+
$scope.vsRepeat.endIndex = options.latch ? _maxEndIndex : __endIndex;
467+
$scope[collectionName] = originalCollection.slice($scope.vsRepeat.startIndex, $scope.vsRepeat.endIndex);
468+
_prevEndIndex = $scope.vsRepeat.endIndex;
469+
$beforeContent.css(getLayoutProp(), 0);
470+
$afterContent.css(getLayoutProp(), 0);
471+
$scope.$emit('vsRenderAllDone');
472+
473+
if ($scope.$root && !$scope.$root.$$phase) {
474+
$scope.$digest();
475+
}
476+
});
476477
});
477478

478479
function reinitialize() {
@@ -498,7 +499,7 @@ function _slicedToArray(arr, i) { if (Array.isArray(arr)) { return arr; } else i
498499
reinitialize();
499500

500501
if ($scope.$root && !$scope.$root.$$phase) {
501-
$scope.$apply();
502+
$scope.$digest();
502503
}
503504
}
504505

@@ -555,6 +556,8 @@ function _slicedToArray(arr, i) { if (Array.isArray(arr)) { return arr; } else i
555556
__startIndex = 0;
556557
__endIndex = 1;
557558
} else {
559+
_warnMismatch();
560+
558561
var relativeScroll = $scrollPosition - options.offsetBefore - scrollOffset;
559562

560563
var _binaryFind = binaryFind($scope.vsRepeat.sizesCumulative, relativeScroll - options.scrollMargin);
@@ -631,6 +634,23 @@ function _slicedToArray(arr, i) { if (Array.isArray(arr)) { return arr; } else i
631634

632635
return digestRequired;
633636
}
637+
638+
function _warnMismatch() {
639+
$scope.$$postDigest(function () {
640+
window.requestAnimationFrame(function () {
641+
var expectedSize = $scope.vsRepeat.sizesCumulative[originalLength];
642+
var compStyle = window.getComputedStyle(repeatContainer[0]);
643+
var paddings = options.horizontal ? ['paddingLeft', 'paddingRight'] : ['paddingTop', 'paddingBottom'];
644+
var containerSize = repeatContainer[0][scrollSize] - paddings.reduce(function (acc, prop) {
645+
return acc + Number(compStyle[prop].slice(0, -2));
646+
}, 0);
647+
648+
if (repeatContainer[0][scrollSize] && expectedSize !== containerSize) {
649+
console.warn('vsRepeat: size mismatch. Expected size ' + expectedSize + 'px whereas actual size is ' + containerSize + 'px. Fix vsSize on element:', $element[0]);
650+
}
651+
});
652+
});
653+
}
634654
}
635655
};
636656
}

0 commit comments

Comments
 (0)