Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

ng-repeat Convert to new change-detection correct unnecessary moves. #728

Closed
@mhevery

Description

@mhevery
 // iit test  
    iit(r'should not move blocks when elements only added or removed',
        inject((Injector injector) {
      var throwOnMove = new MockAnimate();
      var child = injector.createChild([new Module()
          ..value(NgAnimate, throwOnMove) // THIS LINE WILL CAUSE THE TEST TO FAIL
          ]);

      child.invoke((Injector injector, Scope $rootScope, Compiler compiler, DirectiveMap _directives) {
        $exceptionHandler = injector.get(ExceptionHandler);
        scope = $rootScope;
        $compile = (html) {
          element = $(html);
          var viewFactory = compiler(element, _directives);
          var view = viewFactory(injector, element);
          return element;
        };
        directives = _directives;
      });

      element = $compile(
        '<ul>' +
            '<li ng-repeat="item in items">{{item}}</li>' +
        '</ul>');

      // INIT
      scope.context['items'] = ['a', 'b', 'c'];
      scope.apply();

      // GROW
      scope.context['items'].add('d');
      scope.apply();

      // SHRINK
      scope.context['items'].removeLast();
      scope.apply();
      scope.context['items'].removeAt(0);
      scope.apply();
      expect(element.text()).toEqual('bc');
    }));

// Mock animate instance that throws on move
class MockAnimate extends NgAnimate {
  Animation move(Iterable<Node> nodes, Node parent,
            { Node insertBefore }) {
    throw "Move should not be called";
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions