Skip to content

Commit caac098

Browse files
committed
feat(scope): add new createProtoChild method
Internalizes PrototypeMap, and allows for easier switch to ContextLocals.
1 parent 5f20831 commit caac098

File tree

8 files changed

+19
-14
lines changed

8 files changed

+19
-14
lines changed

lib/core/scope.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,11 @@ class Scope {
379379
return child;
380380
}
381381

382+
/// Creates a child [Scope] that is prototypal with respect to current scope.
383+
Scope createProtoChild() {
384+
return createChild(new PrototypeMap(context));
385+
}
386+
382387
/**
383388
* Removes the current scope (and all of its children) from the parent scope. Removal implies
384389
* that calls to [digest] will no longer propagate to the current scope nor its children.

lib/core_dom/view.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ViewPort {
5555
}
5656

5757
View insertNew(ViewFactory viewFactory, { View insertAfter, Scope viewScope}) {
58-
if (viewScope == null) viewScope = scope.createChild(new PrototypeMap(scope.context));
58+
if (viewScope == null) viewScope = scope.createProtoChild();
5959
View view = viewFactory.call(viewScope, directiveInjector);
6060
return insert(view, insertAfter: insertAfter);
6161
}

lib/directive/ng_include.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class NgInclude {
4545

4646
_updateContent(ViewFactory viewFactory) {
4747
// create a new scope
48-
_scope = scope.createChild(new PrototypeMap(scope.context));
48+
_scope = scope.createProtoChild();
4949
_view = viewFactory(_scope, directiveInjector);
5050

5151
_view.nodes.forEach((node) => element.append(node));

lib/directive/ng_repeat.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ class NgRepeat {
172172

173173
addFn((CollectionChangeItem addition) {
174174
changeFunctions[addition.currentIndex] = (index, previousView) {
175-
var childContext = _updateContext(new PrototypeMap(_scope.context), index,length)
175+
var childScope = _scope.createProtoChild();
176+
var childContext = _updateContext(childScope.context, index, length)
176177
..[_valueIdentifier] = addition.item;
177-
var childScope = _scope.createChild(childContext);
178178
var view = views[index] = _boundViewFactory(childScope);
179179
_viewPort.insert(view, insertAfter: previousView);
180180
};
@@ -222,7 +222,7 @@ class NgRepeat {
222222
_views = views;
223223
}
224224

225-
PrototypeMap _updateContext(PrototypeMap context, int index, int length) {
225+
Map _updateContext(Map context, int index, int length) {
226226
var first = (index == 0);
227227
var last = (index == length - 1);
228228
return context

lib/directive/ng_switch.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class NgSwitch {
8181
val = '!$val';
8282
(cases.containsKey(val) ? cases[val] : cases['?'])
8383
.forEach((_Case caze) {
84-
Scope childScope = scope.createChild(new PrototypeMap(scope.context));
84+
Scope childScope = scope.createProtoChild();
8585
var view = caze.viewFactory(childScope);
8686
caze.anchor.insert(view);
8787
currentViews.add(new _ViewScopePair(view, caze.anchor,

lib/routing/ng_view.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class NgView implements DetachAware, RouteProvider {
120120
_viewCache.fromUrl(viewDef.template, newDirectives, Uri.base);
121121
viewFuture.then((ViewFactory viewFactory) {
122122
_cleanUp();
123-
_childScope = _scope.createChild(new PrototypeMap(_scope.context));
123+
_childScope = _scope.createProtoChild();
124124
_view = viewFactory(_childScope, _dirInjector);
125125
_view.nodes.forEach((elm) => _element.append(elm));
126126
});

test/core/scope_spec.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,9 @@ void main() {
238238
});
239239

240240
it('children should point to root', (RootScope rootScope) {
241-
var child = rootScope.createChild(new PrototypeMap(rootScope.context));
241+
var child = rootScope.createProtoChild();
242242
expect(child.rootScope).toEqual(rootScope);
243-
expect(child.createChild(new PrototypeMap(rootScope.context)).rootScope).toEqual(rootScope);
243+
expect(child.createProtoChild().rootScope).toEqual(rootScope);
244244
});
245245
});
246246

@@ -253,11 +253,11 @@ void main() {
253253

254254

255255
it('should point to parent', (RootScope rootScope) {
256-
var child = rootScope.createChild(new PrototypeMap(rootScope.context));
256+
var child = rootScope.createProtoChild();
257257
expect(child.id).toEqual(':0');
258258
expect(rootScope.parentScope).toEqual(null);
259259
expect(child.parentScope).toEqual(rootScope);
260-
expect(child.createChild(new PrototypeMap(rootScope.context)).parentScope).toEqual(child);
260+
expect(child.createProtoChild().parentScope).toEqual(child);
261261
});
262262
});
263263
});
@@ -274,7 +274,7 @@ void main() {
274274

275275
it(r'should add listener for both emit and broadcast events', (RootScope rootScope) {
276276
var log = '',
277-
child = rootScope.createChild(new PrototypeMap(rootScope.context));
277+
child = rootScope.createProtoChild();
278278

279279
eventFn(event) {
280280
expect(event).not.toEqual(null);
@@ -294,7 +294,7 @@ void main() {
294294

295295
it(r'should return a function that deregisters the listener', (RootScope rootScope) {
296296
var log = '';
297-
var child = rootScope.createChild(new PrototypeMap(rootScope.context));
297+
var child = rootScope.createProtoChild();
298298
var subscription;
299299

300300
eventFn(e) {

test/directive/ng_repeat_spec.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ main() {
529529
it('should correctly handle detached state', () {
530530
scope.context['items'] = [1];
531531

532-
var parentScope = scope.createChild(new PrototypeMap(scope.context));
532+
var parentScope = scope.createProtoChild();
533533
element = compile(
534534
'<ul>'
535535
'<li ng-repeat="item in items">{{item}}</li>'

0 commit comments

Comments
 (0)