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

Use scope.watchAST instead of scope.watch #1127

Closed
wants to merge 2 commits into from

Conversation

mvuksano
Copy link
Contributor

@mvuksano mvuksano commented Jun 9, 2014

Fixes #1110

..watch('[a, 2, 3]', (value, previous) => logger(value))
..watch('{a:a, b:2}', (value, previous) => logger(value))
// TODO what do we do with this case?
// ..watchAST(parser(''), (value, previous) => logger(value))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbdeboer What should we do when watching an empty string (''). Parser can't deal with this one yet. Should we modify the parser a bit or not allow watching this specific value?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in AngularJS, we can denote parsed expressions as constant, which instructs them to be unwatched after they're first evaluated.

I'm not sure if there's a similar mechanic in angular.dart, but it seems reasonable that it should behave similarly. (note: currently, AngularJS won't treat a parsed empty string as a constant expression, and the returned function is basically a noop, returns undefined --- so maybe null in dart?)

@mvuksano mvuksano added cla: yes and removed cla: no labels Jun 9, 2014
@jbdeboer
Copy link
Contributor

@markovuksanovic I would leave the tests as is: scope.watch() is basically scope.watchAST(parser(xx)), so we aren't gaining much from adding the explicit call in the tests.

Plus if makes with PR much less scary.

@mvuksano mvuksano changed the title [WIP] Use scope.watchAST instead of scope.watch Use scope.watchAST instead of scope.watch Jun 11, 2014
@mvuksano
Copy link
Contributor Author

@jbdeboer I've reverted changes to tests. This is now ready for review.

@jbdeboer
Copy link
Contributor

The ASTs should be precomputed so we can avoid creating them in the critical path.

@@ -219,7 +220,7 @@ class ElementBinder {
if (directive is AttachAware) {
var taskId = tasks.registerTask();
Watch watch;
watch = scope.watch('1', // Cheat a bit.
watch = scope.watchAST(_astParser('1'), // Cheat a bit.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

precompute

@mvuksano
Copy link
Contributor Author

@jbdeboer I tried computing the asts ahead of time as much as possible. I also tried to cache ast for cases when ast is computed from an expression passed into a function (and cannot be computed ahead of time). Please let me know what you think.

this.componentData, this.decorators,
this.onEvents, this.bindAttrs, this.childMode);
this.onEvents, this.bindAttrs, this.childMode) {
_helperAst = _astParser('1');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compute this in a global service, ElementBinderBuilder, instead of re-computing it for each ElementBinder.

@jbdeboer
Copy link
Contributor

Thanks @markovuksanovic; the '1' change is ElementBinder is good (after fixing the comments). Could you break that into a separate SHA?

For the directives, what we really want is to deprecate the use of Scope.watch() entirely by e.g. adding APIs to the ElementBinder's attribute mappings. That is a much more involved change though. We have been thinking about it a bit:

e.g. in NgClass, we are using Scope.watch() instead of attribute mappings because we need to set collection and canChangeModel on Scope.watch, that is not possible with attribute mappings right now. Instead of adding a cache, we should fix the API.

@vicb
Copy link
Contributor

vicb commented Jun 24, 2014

e.g. in NgClass, we are using Scope.watch() instead of attribute mappings because we need to set collection and canChangeModel on Scope.watch, that is not possible with attribute mappings right now. Instead of adding a cache, we should fix the API.

This is done in the bind- branch, right ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging this pull request may close these issues.

Upgrade all scope.watch calls to scope.watchAST
5 participants