-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatic dependency recognition #386
Comments
Seems interesting. However, I feel like this would probably be pretty fragile and prone to breaking. For instance, what if you did something like:
I know that's a bit contrived, but I can imagine many other similar situations. |
Currently I can think of two solutions:
I don't think about removing Anyways, I'll be glad if someone find elegant solution. |
I don't see anything about @wagenet's example that would break automatic detection. Knockout.js already does this. (Whenever a computed observable is evaluated, it pushes a dependencies array onto a stack, and any observables evaluated during that time are added. Works because JavaScript is single-threaded.) |
@exogen: Ah good point, I was thinking of it in the wrong way. I'm open to someone attempting a pull request for this. I prefer explicit declaration, but we could probably do a half decent job of guessing. I still imagine we'd have problems with things like:
If content is null, the |
@wagenet Knockout handles that case, too – the dependency list isn't determined once, it's updated whenever the observable is re-evaluated. |
The biggest problem with this approach is that it requires executing all computed properties on boot to determine their dependencies. This would be:
I suspect that executing all computed properties for all new objects would be prohibitively expensive. I'd be open for someone to demonstrate that this was not true. |
All I can offer is that Knockout has already solved your concerns, including the multiple complex conditionals, although I can't speak to the "expensive" part. It has the option to defer evaluation of computed properties – there's really no need to determine dependencies on boot vs. during the first evaluation, is there? |
@exogen There's definitely a need to determine dependencies in advance. Otherwise we won't be able to trigger any change notifications until we've done one evaluation. |
If a tree falls in a forest and no one is around to hear it, does it make a sound? If a computed property isn't used, who cares if it changes? |
I think of following counterexample:
Person = Ember.Object.extend({
status: false,
changedAt: Ember.computed(function() {
if(Math.random() > 0.5 || this.get('status')) {
return Date();
}
})
}); |
In those (rare) cases you must just use explicit dependency tracking. |
@judofyr do you understand the concern about needing to execute the computed properties initially to bootstrap the dependencies? |
I don't see the need to bootstrap the dependencies. What I'm trying to say: Nearly all places where you care about updates to computed properties is a place where the property is actually called (e.g. in a view). If you don't call a computed property, there's a big chance you won't need the events either. |
I hate to bump an old thread, but anymore news on this? |
@nathggns @wycats's comment is still our thoughts on this. Some additional thoughts: In theory inferring from syntax will work when it is syntactically obvious, emberscript's |
It's possible to defer dependencies without using the syntax. You can use the use of the |
@nathggns this is true, but the extra complexity of tracking get's during during CP invocation and supporting arbitrary branching within CP's vs annotating the a CP DK's hasn't created a motivating situation. If in fact you are motivated and have the bandwidth, I would invite you investigate this further. |
I'm currently looking at adding computed properties altogether to angular On 22 December 2013 22:19, Stefan Penner notifications@github.com wrote:
Thanks, |
@nathggns - I believe that https://github.com/gunn/ember-auto implements some nice improvements to reduce much of the duplication. |
I'd rather get them inline to be honest. Sent from my iPhone
|
This is one of the things Ember devs should be looking into going forward, IMO. It is how React and Vue work and it is night and day in terms of simplicity and power. The sort of things you can achieve with computed properties in those frameworks are impossible in Ember or just not worth the effort. Enough with the feature-less releases that we've been getting for the past 2-3 years. Do something interesting, please. |
Like, the problem where you can't have nested |
There is a PR to Glimmer's object model that does this: glimmerjs/glimmer-component#61. I believe it is blocked on getting benchmarks to be sure we didn't cause a regression. It is not likely that this feature would land on the current Ember object model. Instead the ES Classes RFC starts our slow migration away from being coupled to Ember's object model. The Glimmer object model can possibly replace it once we've gone a bit further. Thanks for the feedback @rhyek. |
Clarify deprecations of private API
How about automatic recognizing (on first run) in
Ember.computed
body function what dependencies it uses?See the example from docs:
My idea is to reprogram
this.get
method so they'd automatically addproperty
dependencies if executed in context ofEmber.computed
, so above code would become shorter and more coffee-script friendly:Oh. And use of
property()
method onEmber.computed
would disable this behavior so code would be backward-compatible and customizable if needed to.What do you think?
The text was updated successfully, but these errors were encountered: