JSFiddle - React, Tailwind, and code Playground
HTML
<h1>Is ngRepeat smart?</h1>
<div ng-app="test" ng-controller="test">
<span>
<div ng-repeat="e in f">{{e}}</div>
</span>
<input type="button" ng-click="am()" value="Run test - add things in the middle"/>
<input type="button" ng-click="af()" value="Run test - add things in the front"/>
<input type="button" ng-click="ab()" value="Run test - add things in the back"/>
<input type="button" ng-click="aa()" value="Run test - add things in the back, middle and front"/>
<input type="button" ng-click="rm()" value="Run test - remove things in the middle"/>
<input type="button" ng-click="rf()" value="Run test - remove things in the front"/>
<input type="button" ng-click="rb()" value="Run test - remove things in the back"/>
<input type="button" ng-click="ra()" value="Run test - remove things from the back, middle and front"/>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js"></script>
JavaScript
function test(la, lb){
for (var i = 0; i < la.length; i++){
if (la[i] !== lb[i]){
window.alert("FAILED!")
return;
}
}
window.alert("Passed :)")
}
function get_copy(){
var a = []
var html_collection = document.querySelector("span").children;
// this will create a static shallow copy of the children list. html_collection is live.
for (var i = 0; i < html_collection.length; i++){
a.push(html_collection[i])
}
return a
}
angular.module("test", []).controller("test",function ($scope, $timeout){
$scope.f = [1,2,3,4,5,6,7]
$scope.am = function (){
var a = get_copy()
$scope.f.splice(2, 0, 999, 998, 997);
$timeout(function (){ // wait for the dom to render after the previous step
var b = get_copy()
b.splice(2,3)
test(a,b)
$scope.f = [1,2,3,4,5,6,7]
});
}
$scope.af = function (){
var a = get_copy()
$scope.f.splice(0, 0, 999, 998, 997);
$timeout(function (){ // wait for the dom to render after the previous step
var b = get_copy()
b.splice(0,3)
test(a,b)
$scope.f = [1,2,3,4,5,6,7]
});
}
$scope.ab = function (){
var a = get_copy()
$scope.f.push(...[994, 995, 996]);
$timeout(function (){ // wait for the dom to render after the previous step
var b = get_copy()
console.log(b)
b.splice(-3, 3)
test(a,b)
$scope.f = [1,2,3,4,5,6,7]
});
}
$scope.aa = function (){
var a = get_copy()
$scope.f.splice(0, 0, 999, 998, 997);
$scope.f.splice(4, 0, 993, 992, 991);
$scope.f.push(...[994, 995, 996]);
$timeout(function (){ // wait for the dom to render after the previous step
var b = get_copy()
console.log(b)
b.splice(-3, 3)
b.splice(4, 3)
...