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

feature(directive_injector): add View to DirectiveInjector #1293

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions lib/core_dom/directive_injector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class DirectiveInjector implements DirectiveBinder {
final Animate _animate;
final EventHandler _eventHandler;
Scope scope; //TODO(misko): this should be final after we get rid of controller
final View _view;

NgElement _ngElement;
ElementProbe _elementProbe;
Expand Down Expand Up @@ -144,15 +145,18 @@ class DirectiveInjector implements DirectiveBinder {

static Binding _tempBinding = new Binding();

DirectiveInjector(this._parent, appInjector, this._node, this._nodeAttrs,
this._eventHandler, this.scope, this._animate)
: _appInjector = appInjector;
DirectiveInjector(DirectiveInjector parent, appInjector, this._node, this._nodeAttrs,
this._eventHandler, this.scope, this._animate, [View view])
: _parent = parent,
_appInjector = appInjector,
_view = view == null && parent != null ? parent._view : view;

DirectiveInjector._default(this._parent, this._appInjector)
: _node = null,
_nodeAttrs = null,
_eventHandler = null,
scope = null,
_view = null,
_animate = null;

void bind(key, {dynamic toValue: DEFAULT_VALUE,
Expand Down Expand Up @@ -295,6 +299,7 @@ class DirectiveInjector implements DirectiveBinder {
currentInjector = currentInjector._parent;
}
return null;
case VIEW_KEY_ID: return _view;
default: new NoProviderError(_KEYS[keyId]);
}
}
Expand Down Expand Up @@ -375,8 +380,8 @@ class TemplateDirectiveInjector extends DirectiveInjector {

TemplateDirectiveInjector(DirectiveInjector parent, Injector appInjector,
Node node, NodeAttrs nodeAttrs, EventHandler eventHandler,
Scope scope, Animate animate, this._viewFactory)
: super(parent, appInjector, node, nodeAttrs, eventHandler, scope, animate);
Scope scope, Animate animate, this._viewFactory, [View view])
: super(parent, appInjector, node, nodeAttrs, eventHandler, scope, animate, view);


Object _getById(int keyId) {
Expand All @@ -400,9 +405,9 @@ class ComponentDirectiveInjector extends DirectiveInjector {

ComponentDirectiveInjector(DirectiveInjector parent, Injector appInjector,
EventHandler eventHandler, Scope scope,
this._templateLoader, this._shadowRoot, this._contentPort)
this._templateLoader, this._shadowRoot, this._contentPort, [View view])
: super(parent, appInjector, parent._node, parent._nodeAttrs, eventHandler, scope,
parent._animate) {
parent._animate, view) {
// A single component creates a ComponentDirectiveInjector and its DirectiveInjector parent,
// so parent should never be null.
assert(parent != null);
Expand Down
4 changes: 2 additions & 2 deletions lib/core_dom/element_binder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ class ElementBinder {
eventHandler(parentInjector);
if (this is TemplateElementBinder) {
nodeInjector = new TemplateDirectiveInjector(parentInjector, _appInjector,
node, nodeAttrs, parentEventHandler, scope, _animate, (this as TemplateElementBinder).templateViewFactory);
node, nodeAttrs, parentEventHandler, scope, _animate, (this as TemplateElementBinder).templateViewFactory, view);
} else {
nodeInjector = new DirectiveInjector(parentInjector, _appInjector, node, nodeAttrs, parentEventHandler, scope, _animate);
nodeInjector = new DirectiveInjector(parentInjector, _appInjector, node, nodeAttrs, parentEventHandler, scope, _animate, view);
}

for(var i = 0; i < directiveRefs.length; i++) {
Expand Down
6 changes: 3 additions & 3 deletions lib/core_dom/shadow_dom_component_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ class BoundShadowDomComponentFactory implements BoundComponentFactory {
}

List<Key> get callArgs => _CALL_ARGS;
static final _CALL_ARGS = [DIRECTIVE_INJECTOR_KEY, SCOPE_KEY, NG_BASE_CSS_KEY,
static final _CALL_ARGS = [DIRECTIVE_INJECTOR_KEY, SCOPE_KEY, VIEW_KEY, NG_BASE_CSS_KEY,
EVENT_HANDLER_KEY];
Function call(dom.Element element) {
return (DirectiveInjector injector, Scope scope, NgBaseCss baseCss,
return (DirectiveInjector injector, Scope scope, View view, NgBaseCss baseCss,
EventHandler _) {
var s = traceEnter(View_createComponent);
try {
Expand Down Expand Up @@ -166,7 +166,7 @@ class BoundShadowDomComponentFactory implements BoundComponentFactory {
var eventHandler = new ShadowRootEventHandler(
shadowDom, injector.getByKey(EXPANDO_KEY), injector.getByKey(EXCEPTION_HANDLER_KEY));
shadowInjector = new ComponentDirectiveInjector(injector, _injector, eventHandler, shadowScope,
templateLoader, shadowDom, null);
templateLoader, shadowDom, null, view);
shadowInjector.bindByKey(_ref.typeKey, _ref.factory, _ref.paramKeys, _ref.annotation.visibility);

if (_componentFactory.config.elementProbeEnabled) {
Expand Down
6 changes: 3 additions & 3 deletions lib/core_dom/transcluding_component_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class BoundTranscludingComponentFactory implements BoundComponentFactory {
}

List<Key> get callArgs => _CALL_ARGS;
static var _CALL_ARGS = [ DIRECTIVE_INJECTOR_KEY, SCOPE_KEY,
static var _CALL_ARGS = [ DIRECTIVE_INJECTOR_KEY, SCOPE_KEY, VIEW_KEY,
VIEW_CACHE_KEY, HTTP_KEY, TEMPLATE_CACHE_KEY,
DIRECTIVE_MAP_KEY, NG_BASE_CSS_KEY, EVENT_HANDLER_KEY];
Function call(dom.Node node) {
Expand All @@ -107,7 +107,7 @@ class BoundTranscludingComponentFactory implements BoundComponentFactory {
_component.cssUrls.isEmpty);

var element = node as dom.Element;
return (DirectiveInjector injector, Scope scope,
return (DirectiveInjector injector, Scope scope, View view,
ViewCache viewCache, Http http, TemplateCache templateCache,
DirectiveMap directives, NgBaseCss baseCss, EventHandler eventHandler) {

Expand Down Expand Up @@ -145,7 +145,7 @@ class BoundTranscludingComponentFactory implements BoundComponentFactory {

childInjector = new ComponentDirectiveInjector(injector, this._injector,
eventHandler, shadowScope, templateLoader, new ShadowlessShadowRoot(element),
contentPort);
contentPort, view);
childInjector.bindByKey(_ref.typeKey, _ref.factory, _ref.paramKeys, _ref.annotation.visibility);

if (childInjectorCompleter != null) {
Expand Down
13 changes: 9 additions & 4 deletions test/core_dom/directive_injector_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ void main() {
describe('base', () {
DirectiveInjector injector;
Scope scope;
View view;
Animate animate;

addDirective(Type type, [Visibility visibility]) {
Expand All @@ -30,13 +31,16 @@ void main() {
beforeEach((Scope _scope, Animate _animate) {
scope = _scope;
animate = _animate;
injector = new DirectiveInjector(null, appInjector, div, new NodeAttrs(div), eventHandler, scope, animate);
view = new View([], scope);
injector = new DirectiveInjector(null, appInjector, div, new NodeAttrs(div), eventHandler,
scope, animate, view);
});

it('should return basic types', () {
expect(injector.scope).toBe(scope);
expect(injector.get(Injector)).toBe(appInjector);
expect(injector.get(Scope)).toBe(scope);
expect((injector.get(View))).toBe(view);
expect(injector.get(Node)).toBe(div);
expect(injector.get(Element)).toBe(div);
expect((injector.get(NodeAttrs) as NodeAttrs).element).toBe(div);
Expand All @@ -48,7 +52,8 @@ void main() {
it('should support get from parent methods', () {
var newDiv = new DivElement();
var childInjector = new DirectiveInjector(
injector, appInjector, newDiv, new NodeAttrs(newDiv), eventHandler, scope, animate);
injector, appInjector, newDiv, new NodeAttrs(newDiv), eventHandler,
scope, animate, view);

expect(childInjector.get(Node)).toBe(newDiv);
expect(childInjector.getFromParent(Node)).toBe(div);
Expand Down Expand Up @@ -79,8 +84,8 @@ void main() {
DirectiveInjector leafInjector;

beforeEach(() {
childInjector = new DirectiveInjector(injector, appInjector, span, null, null, null, null);
leafInjector = new DirectiveInjector(childInjector, appInjector, span, null, null, null, null);
childInjector = new DirectiveInjector(injector, appInjector, span, null, null, null, null, null);
leafInjector = new DirectiveInjector(childInjector, appInjector, span, null, null, null, null, null);
});

it('should not allow reseting visibility', () {
Expand Down
2 changes: 1 addition & 1 deletion test/directive/ng_model_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void main() {

beforeEach((TestBed tb) {
_ = tb;
dirInjector = new DirectiveInjector(null, _.injector, null, null, null, null, null);
dirInjector = new DirectiveInjector(null, _.injector, null, null, null, null, null, null);
});

describe('type="text" like', () {
Expand Down