refactor(directives): directives use declare that they listen to onChange in the annotations

This commit is contained in:
vsavkin
2015-02-06 13:19:47 -08:00
parent ee3f709fbf
commit 9240b09011
7 changed files with 91 additions and 27 deletions

View File

@ -330,14 +330,25 @@ export function main() {
expect(inj.get(SimpleDirective)).toBeAnInstanceOf(SimpleDirective);
});
it("should allow for direct access using getAtIndex", function () {
it("should allow for direct access using getDirectiveAtIndex", function () {
var inj = injector([
DirectiveBinding.createFromBinding(bind(SimpleDirective).toClass(SimpleDirective), null)
]);
expect(inj.getAtIndex(0)).toBeAnInstanceOf(SimpleDirective);
expect(() => inj.getAtIndex(-1)).toThrowError(
expect(inj.getDirectiveAtIndex(0)).toBeAnInstanceOf(SimpleDirective);
expect(() => inj.getDirectiveAtIndex(-1)).toThrowError(
'Index -1 is out-of-bounds.');
expect(() => inj.getAtIndex(10)).toThrowError(
expect(() => inj.getDirectiveAtIndex(10)).toThrowError(
'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.');
});

View File

@ -1,10 +1,9 @@
import {describe, xit, it, expect, beforeEach, ddescribe, iit, el} from 'angular2/test_lib';
import {ProtoView, ElementPropertyMemento, DirectivePropertyMemento} from 'angular2/src/core/compiler/view';
import {ProtoElementInjector, ElementInjector} from 'angular2/src/core/compiler/element_injector';
import {ProtoElementInjector, ElementInjector, DirectiveBinding} from 'angular2/src/core/compiler/element_injector';
import {EmulatedShadowDomStrategy, NativeShadowDomStrategy} from 'angular2/src/core/compiler/shadow_dom_strategy';
import {DirectiveMetadataReader} from 'angular2/src/core/compiler/directive_metadata_reader';
import {Component, Decorator, Template} from 'angular2/src/core/annotations/annotations';
import {OnChange} from 'angular2/core';
import {Component, Decorator, Template, Directive, onChange} from 'angular2/src/core/annotations/annotations';
import {Lexer, Parser, DynamicProtoChangeDetector,
ChangeDetector} from 'angular2/change_detection';
import {TemplateConfig} from 'angular2/src/core/annotations/template_config';
@ -546,7 +545,9 @@ export function main() {
var pv = new ProtoView(el('<div class="ng-binding"></div>'),
new DynamicProtoChangeDetector(), null);
pv.bindElement(new ProtoElementInjector(null, 0, [DirectiveImplementingOnChange]));
pv.bindElement(new ProtoElementInjector(null, 0, [
DirectiveBinding.createFromType(DirectiveImplementingOnChange, new Directive({lifecycle: [onChange]}))
]));
pv.bindDirectiveProperty( 0, parser.parseBinding('a', null), 'a', reflector.setter('a'), false);
pv.bindDirectiveProperty( 0, parser.parseBinding('b', null), 'b', reflector.setter('b'), false);
createViewAndChangeDetector(pv);
@ -563,7 +564,9 @@ export function main() {
var pv = new ProtoView(el('<div class="ng-binding"></div>'),
new DynamicProtoChangeDetector(), null);
pv.bindElement(new ProtoElementInjector(null, 0, [DirectiveImplementingOnChange]));
pv.bindElement(new ProtoElementInjector(null, 0, [
DirectiveBinding.createFromType(DirectiveImplementingOnChange, new Directive({lifecycle: [onChange]}))
]));
pv.bindDirectiveProperty( 0, parser.parseBinding('a', null), 'a', reflector.setter('a'), false);
pv.bindDirectiveProperty( 0, parser.parseBinding('b', null), 'b', reflector.setter('b'), false);
createViewAndChangeDetector(pv);
@ -616,7 +619,7 @@ class SomeDirective {
}
}
class DirectiveImplementingOnChange extends OnChange {
class DirectiveImplementingOnChange {
a;
b;
c;