-
Notifications
You must be signed in to change notification settings - Fork 248
Ease Angular adoption: support a *simple* CDA based on equality (in addition to the new CDA) #705
Comments
This is an issue in AngularJS with the 1.x scope implementation as well (although ng-repeat uses a special watch algorithm to make this less of an issue), but functions returning new object instances causes model instability, and that's relatively well understood. It can be very expensive to perform an exact comparison between the old object instance and the new object instance, so it's sort of hard to get this right. /subscribes to thread, interested in thoughts on this |
So the issue with the But in your case there is a simple solution. Just define a |
Btw, I understand the arguments regarding efficiency and I am in agreement with them. Let me state this issue another: in the Change Detection document you point out that AngularDart's design should (or could?) support different CDAs (possibly plugged-in via DI or provided natively be a VM). Currently, as far as I can tell, the design does not support CDA plug-in because some core parts of the CDA are duplicated in the code; e.g., var last = currentValue;
if (!identical(last, current)) {
if (last is String && current is String &&
last == current) {
// This is false change in strings we need to recover, and pretend it
// is the same. We save the value so that next time identity will pass
currentValue = current;
} else if (last is num && last.isNaN && current is num && current.isNaN) {
// we need this for the compiled JavaScript since in JS NaN !== NaN.
} else {
previousValue = last;
currentValue = current;
return true;
}
}
return false;
} Thanks for mentioning function purity, that gives me a few ideas (and it helps me that this bug is now fixed). |
Not consistent with the current Angular design goals. |
Executive summary
While I used to be able to write a single
ng-repeat
collection expression likenames.split(',')
in my HTML file, it seems that under Angular's new Change Detection Algorithm (CDA) I have to replace that by a custom 10-line-or-so@NgController
that implements caching. This will not aid AngularDart adoption. I admired Angular because it allowed me to focus on web app design rather than writing boilerplate code, but this seems to be a step backwards. Details are given below.A solution I propose is to have Angular support at least two CDAs: one which is the simplest possible to use (automatic family sedan version) and then the new CDA (turbocharged formula 1 version, ... or think "Jeep without doors or safety belts") targeted for experts ;).
DETAILS
I believe that a selling point of Dart is that it gives its users choices. Consider types as one example: to quote Gilad Bracha in his concluding remarks to Optional Types in Dart:
Since January I have been teaching a graduate course in Dart and AngularDart. Up until the the introduction of the new Change Detection Algorithm (CDA) of v0.9.9, I was able to develop considerable lecture material supported by examples without any surprises. In particular, it was pleasant to see that simple web apps were simple to write.
I understand that the new CDA is highly optimized so that it can support:
per millisecond [1], but this comes at the cost of rendering many simple intuitively-correct web apps either completely invalid or requiring considerable rewrite. I give an example of each case below.
Example: Simple app that is now invalid
I have a suite of elementary examples illustrating basic functionality of AngularDart without the use of custom controllers. Here is one example:
This runs nicely under 0.9.8:
Now under the new CDA we get the following error:
The message is complaining that the list
[Alice, Bob]
isn't the same as the list[Alice, Bob]
. This will confuse most newcomers. What is happening is that the new CDA doesn't like that the expressionnames.split(',')
yields a new list instance every time it is evaluated --- despite the fact that it generates the same list value every time.Under the new CDA, I see no solution to this other than writing a customer controller. Let's try that next.
Example: Restrictions on custom controllers
A first try at writing a custom controller to solve the problem illustrated above might be:
with corresponding changes to the HTML
But this yields the same warning we got before: Observer reaction functions should not change model.
I raised this issue earlier (#641), in which I gave a different example of a controller that generated a list of
int
values:and the response was that under the new CDA I need write something like
Is this really the simplest possible solution under the new CDA? While I admired Angular because it allowed one to focus on web app design rather than writing boilerplate code, this seems to be a step backwards. This will not help the adoption of AngularDart.
A Possible Solution
The main problem, IMHO, is the belief that "one size fits all" when it comes to CDA. I think that there should be at least two CDAs:
with the former being the default.
[1] Change Detection. Status: Draft. Accessed March 11, 2014. Author: Misko Hevery
The text was updated successfully, but these errors were encountered: