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

Commit

Permalink
fix(scope): createChild now requires context
Browse files Browse the repository at this point in the history
  • Loading branch information
mhevery committed Feb 20, 2014
1 parent 6176ba3 commit 6722e1a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
3 changes: 1 addition & 2 deletions lib/core/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ class Scope {
ScopeStream on(String name) =>
_Streams.on(this, rootScope._exceptionHandler, name);

Scope createChild([Object childContext]) {
if (childContext == null) childContext = context;
Scope createChild(Object childContext) {
var child = new Scope(childContext, rootScope, this,
_depth + 1, _nextChildIndex++,
watchGroup.newGroup(childContext),
Expand Down
6 changes: 4 additions & 2 deletions lib/core_dom/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ class DirectiveRef {
* services from the provided modules.
*/
Injector forceNewDirectivesAndFilters(Injector injector, List<Module> modules) {
modules.add(new Module()
..factory(Scope, (i) => i.parent.get(Scope).createChild()));
modules.add(new Module()..factory(Scope, (i) {
var scope = i.parent.get(Scope);
return scope.createChild(new PrototypeMap(scope.context));
}));
return injector.createChild(modules,
forceNewInstances: [DirectiveMap, FilterMap]);
}
12 changes: 6 additions & 6 deletions test/core/scope_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ main() => describe('scope', () {
}));

it('children should point to root', inject((RootScope rootScope) {
var child = rootScope.createChild();
var child = rootScope.createChild(new PrototypeMap(rootScope.context));
expect(child.rootScope).toEqual(rootScope);
expect(child.createChild().rootScope).toEqual(rootScope);
expect(child.createChild(new PrototypeMap(rootScope.context)).rootScope).toEqual(rootScope);
}));
});

Expand All @@ -206,10 +206,10 @@ main() => describe('scope', () {


it('should point to parent', inject((RootScope rootScope) {
var child = rootScope.createChild();
var child = rootScope.createChild(new PrototypeMap(rootScope.context));
expect(rootScope.parentScope).toEqual(null);
expect(child.parentScope).toEqual(rootScope);
expect(child.createChild().parentScope).toEqual(child);
expect(child.createChild(new PrototypeMap(rootScope.context)).parentScope).toEqual(child);
}));
});
});
Expand All @@ -226,7 +226,7 @@ main() => describe('scope', () {

it(r'should add listener for both emit and broadcast events', inject((RootScope rootScope) {
var log = '',
child = rootScope.createChild();
child = rootScope.createChild(new PrototypeMap(rootScope.context));

eventFn(event) {
expect(event).not.toEqual(null);
Expand All @@ -246,7 +246,7 @@ main() => describe('scope', () {

it(r'should return a function that deregisters the listener', inject((RootScope rootScope) {
var log = '';
var child = rootScope.createChild();
var child = rootScope.createChild(new PrototypeMap(rootScope.context));
var subscription;

eventFn(e) {
Expand Down

0 comments on commit 6722e1a

Please sign in to comment.