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

Commit a33891e

Browse files
committed
perf(element binder): Do not create tasklists when not needed
This code was originally authored by @mhevery in the DirectiveInjector change.
1 parent 57da29d commit a33891e

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

lib/core_dom/element_binder.dart

+12-12
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class ElementBinder {
7777

7878
void _bindTwoWay(tasks, AST ast, scope, directiveScope,
7979
controller, AST dstAST) {
80-
var taskId = tasks.registerTask();
80+
var taskId = (tasks != null) ? tasks.registerTask() : 0;
8181

8282
var viewOutbound = false;
8383
var viewInbound = false;
@@ -86,7 +86,7 @@ class ElementBinder {
8686
viewOutbound = true;
8787
scope.rootScope.runAsync(() => viewOutbound = false);
8888
var value = dstAST.parsedExp.assign(controller, inboundValue);
89-
tasks.completeTask(taskId);
89+
if (tasks != null) tasks.completeTask(taskId);
9090
return value;
9191
}
9292
});
@@ -96,18 +96,18 @@ class ElementBinder {
9696
viewInbound = true;
9797
scope.rootScope.runAsync(() => viewInbound = false);
9898
ast.parsedExp.assign(scope.context, outboundValue);
99-
tasks.completeTask(taskId);
99+
if (tasks != null) tasks.completeTask(taskId);
100100
}
101101
});
102102
}
103103
}
104104

105105
_bindOneWay(tasks, ast, scope, AST dstAST, controller) {
106-
var taskId = tasks.registerTask();
106+
var taskId = (tasks != null) ? tasks.registerTask() : 0;
107107

108108
scope.watchAST(ast, (v, _) {
109109
dstAST.parsedExp.assign(controller, v);
110-
tasks.completeTask(taskId);
110+
if (tasks != null) tasks.completeTask(taskId);
111111
});
112112
}
113113

@@ -148,10 +148,10 @@ class ElementBinder {
148148

149149
switch (p.mode) {
150150
case '@': // string
151-
var taskId = tasks.registerTask();
151+
var taskId = (tasks != null) ? tasks.registerTask() : 0;
152152
nodeAttrs.observe(attrName, (value) {
153153
dstAST.parsedExp.assign(directive, value);
154-
tasks.completeTask(taskId);
154+
if (tasks != null) tasks.completeTask(taskId);
155155
});
156156
break;
157157

@@ -207,26 +207,26 @@ class ElementBinder {
207207
scope.context[(ref.annotation as Controller).publishAs] = directive;
208208
}
209209

210-
var tasks = new _TaskList(directive is AttachAware ? () {
210+
var tasks = directive is AttachAware ? new _TaskList(() {
211211
if (scope.isAttached) directive.attach();
212-
} : null);
212+
}) : null;
213213

214214
if (ref.mappings.isNotEmpty) {
215215
if (nodeAttrs == null) nodeAttrs = new _AnchorAttrs(ref);
216216
_createAttrMappings(directive, scope, ref.mappings, nodeAttrs, tasks);
217217
}
218218

219219
if (directive is AttachAware) {
220-
var taskId = tasks.registerTask();
220+
var taskId = (tasks != null) ? tasks.registerTask() : 0;
221221
Watch watch;
222222
watch = scope.watch('1', // Cheat a bit.
223223
(_, __) {
224224
watch.remove();
225-
tasks.completeTask(taskId);
225+
if (tasks != null) tasks.completeTask(taskId);
226226
});
227227
}
228228

229-
tasks.doneRegistering();
229+
if (tasks != null) tasks.doneRegistering();
230230

231231
if (directive is DetachAware) {
232232
scope.on(ScopeEvent.DESTROY).listen((_) => directive.detach());

0 commit comments

Comments
 (0)