feat(change_detection): added a directive lifecycle hook that is called after children are checked
This commit is contained in:
@ -222,6 +222,18 @@ export function main() {
|
||||
|
||||
expect(protoChild.directParent()).toEqual(null);
|
||||
});
|
||||
|
||||
it("should allow for direct access using getDirectiveBindingAtIndex", function () {
|
||||
var binding = DirectiveBinding.createFromBinding(
|
||||
bind(SimpleDirective).toClass(SimpleDirective), null);
|
||||
var proto = new ProtoElementInjector(null, 0, [binding]);
|
||||
|
||||
expect(proto.getDirectiveBindingAtIndex(0)).toBeAnInstanceOf(DirectiveBinding);
|
||||
expect(() => proto.getDirectiveBindingAtIndex(-1)).toThrowError(
|
||||
'Index -1 is out-of-bounds.');
|
||||
expect(() => proto.getDirectiveBindingAtIndex(10)).toThrowError(
|
||||
'Index 10 is out-of-bounds.');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -419,17 +431,6 @@ export function main() {
|
||||
'Index 10 is out-of-bounds.');
|
||||
});
|
||||
|
||||
it("should allow for direct access using getBindingAtIndex", function () {
|
||||
var inj = injector([
|
||||
DirectiveBinding.createFromBinding(bind(SimpleDirective).toClass(SimpleDirective), null)
|
||||
]);
|
||||
expect(inj.getDirectiveBindingAtIndex(0)).toBeAnInstanceOf(DirectiveBinding);
|
||||
expect(() => inj.getDirectiveBindingAtIndex(-1)).toThrowError(
|
||||
'Index -1 is out-of-bounds.');
|
||||
expect(() => inj.getDirectiveBindingAtIndex(10)).toThrowError(
|
||||
'Index 10 is out-of-bounds.');
|
||||
});
|
||||
|
||||
it("should handle cyclic dependencies", function () {
|
||||
expect(() => {
|
||||
var bAneedsB = bind(A_Needs_B).toFactory((a) => new A_Needs_B(a), [B_Needs_A]);
|
||||
|
@ -11,7 +11,7 @@ import {DynamicProtoChangeDetector, ChangeDetector, Lexer, Parser} from 'angular
|
||||
|
||||
function createView(nodes) {
|
||||
var view = new View(null, nodes, MapWrapper.create());
|
||||
var cd = new DynamicProtoChangeDetector(null).instantiate(view, [], null);
|
||||
var cd = new DynamicProtoChangeDetector(null).instantiate(view, [], null, []);
|
||||
view.init(cd, [], [], [], [], [], [], [], [], []);
|
||||
return view;
|
||||
}
|
||||
|
25
modules/angular2/test/core/compiler/view_spec.js
vendored
25
modules/angular2/test/core/compiler/view_spec.js
vendored
@ -3,7 +3,7 @@ import {ProtoView, ElementPropertyMemento, DirectivePropertyMemento} from 'angul
|
||||
import {ProtoElementInjector, ElementInjector, DirectiveBinding} from 'angular2/src/core/compiler/element_injector';
|
||||
import {EmulatedScopedShadowDomStrategy, NativeShadowDomStrategy} from 'angular2/src/core/compiler/shadow_dom_strategy';
|
||||
import {DirectiveMetadataReader} from 'angular2/src/core/compiler/directive_metadata_reader';
|
||||
import {Component, Decorator, Viewport, Directive, onChange} from 'angular2/src/core/annotations/annotations';
|
||||
import {Component, Decorator, Viewport, Directive, onChange, onAllChangesDone} from 'angular2/src/core/annotations/annotations';
|
||||
import {Lexer, Parser, DynamicProtoChangeDetector,
|
||||
ChangeDetector} from 'angular2/change_detection';
|
||||
import {EventEmitter} from 'angular2/src/core/annotations/di';
|
||||
@ -627,6 +627,21 @@ export function main() {
|
||||
cd.detectChanges();
|
||||
expect(directive.changes).toEqual({"a" : new PropertyUpdate(100, 0)});
|
||||
});
|
||||
|
||||
it('should invoke the onAllChangesDone callback', () => {
|
||||
var pv = new ProtoView(el('<div class="ng-binding"></div>'),
|
||||
new DynamicProtoChangeDetector(null), null);
|
||||
|
||||
pv.bindElement(null, 0, new ProtoElementInjector(null, 0, [
|
||||
DirectiveBinding.createFromType(DirectiveImplementingOnAllChangesDone, new Directive({lifecycle: [onAllChangesDone]}))
|
||||
]));
|
||||
|
||||
createViewAndChangeDetector(pv);
|
||||
cd.detectChanges();
|
||||
|
||||
var directive = view.elementInjectors[0].get(DirectiveImplementingOnAllChangesDone);
|
||||
expect(directive.onAllChangesDoneCalled).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -678,6 +693,14 @@ class DirectiveImplementingOnChange {
|
||||
}
|
||||
}
|
||||
|
||||
class DirectiveImplementingOnAllChangesDone {
|
||||
onAllChangesDoneCalled;
|
||||
|
||||
onAllChangesDone() {
|
||||
this.onAllChangesDoneCalled = true;
|
||||
}
|
||||
}
|
||||
|
||||
class SomeService {}
|
||||
|
||||
@Component({services: [SomeService]})
|
||||
|
Reference in New Issue
Block a user