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

Commit

Permalink
perf(element binder): Do not create tasklists when not needed
Browse files Browse the repository at this point in the history
This code was originally authored by @mhevery in the
DirectiveInjector change.
  • Loading branch information
jbdeboer committed Jul 9, 2014
1 parent 57da29d commit a33891e
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/core_dom/element_binder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ElementBinder {

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

var viewOutbound = false;
var viewInbound = false;
Expand All @@ -86,7 +86,7 @@ class ElementBinder {
viewOutbound = true;
scope.rootScope.runAsync(() => viewOutbound = false);
var value = dstAST.parsedExp.assign(controller, inboundValue);
tasks.completeTask(taskId);
if (tasks != null) tasks.completeTask(taskId);
return value;
}
});
Expand All @@ -96,18 +96,18 @@ class ElementBinder {
viewInbound = true;
scope.rootScope.runAsync(() => viewInbound = false);
ast.parsedExp.assign(scope.context, outboundValue);
tasks.completeTask(taskId);
if (tasks != null) tasks.completeTask(taskId);
}
});
}
}

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

scope.watchAST(ast, (v, _) {
dstAST.parsedExp.assign(controller, v);
tasks.completeTask(taskId);
if (tasks != null) tasks.completeTask(taskId);
});
}

Expand Down Expand Up @@ -148,10 +148,10 @@ class ElementBinder {

switch (p.mode) {
case '@': // string
var taskId = tasks.registerTask();
var taskId = (tasks != null) ? tasks.registerTask() : 0;
nodeAttrs.observe(attrName, (value) {
dstAST.parsedExp.assign(directive, value);
tasks.completeTask(taskId);
if (tasks != null) tasks.completeTask(taskId);
});
break;

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

var tasks = new _TaskList(directive is AttachAware ? () {
var tasks = directive is AttachAware ? new _TaskList(() {
if (scope.isAttached) directive.attach();
} : null);
}) : null;

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

if (directive is AttachAware) {
var taskId = tasks.registerTask();
var taskId = (tasks != null) ? tasks.registerTask() : 0;
Watch watch;
watch = scope.watch('1', // Cheat a bit.
(_, __) {
watch.remove();
tasks.completeTask(taskId);
if (tasks != null) tasks.completeTask(taskId);
});
}

tasks.doneRegistering();
if (tasks != null) tasks.doneRegistering();

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

0 comments on commit a33891e

Please sign in to comment.