-
Notifications
You must be signed in to change notification settings - Fork 17
Computed properties still can't fully express all dependencies. Consider some mechanism of imperatively directing them to update #31
Comments
The actual code that led here: This version works well until the user modifies some sub-structures in object, then there are only bad options for forcing it to update: <polymer-element name="json-dump" extends="pre" attributes="object">
<template><code>{{object | stringify}}</code></template>
<script>
Polymer('json-dump', {
stringify: function(object) {
return JSON.stringify(object, null, ' ');
}
});
</script>
</polymer-element> When I represent the data as a computed-property instead of filtered data, I have an entry-point to force an update ( <polymer-element name="json-dump" extends="pre" attributes="object">
<template><code>{{stringified}}</code></template>
<script>
Polymer('json-dump', {
objectChanged: function() {
this.stringify();
},
stringify: function() {
this.stringified = JSON.stringify(this.object, null, ' ');
}
});
</script>
</polymer-element> The former construction is superior IMO (more compact, doesn't need |
Scott, can we close this now that we have inline function support (and the idea to add a dependency which you can "kick")? |
It's possible I'm not understanding fully, but it seems like a hack to make a faux property to kick the template. Is it against the grain for the template to have kickability via a function? If so, then at least I believe we need to design a helper at a higher level to hide the actual details. |
It's totally a hack. Literally touching (read) the computed properties (as they are now), will cause them to update also by pulling their dependencies, noticing they have changed and re-computing. We can discuss other options. I'll go ahead and change the title of this bug to something more presently precise |
I may not be understanding, but it seems like there's a few possible routes to addressing this:
Did I get that right? It sounds like the first one would be better (from a Polymer perspective) as it wouldn't require a faux property whose reason for existence is to kick the template. Not sure the implications towards adding this to TemplateBinding, though. |
We are using a gettext-style translation system where a template might have things like
then we added the PolymerExpression translate with
This all works good. Now, if the user decides to change the language, the translateFunction needs to be re-run for the template. Maybe a better way to handle this would be to somehow reset the Polymer expression "translate" and that the template binding system would automatically re-render all templates that uses that expression.
|
Hello @nomego, did you find a proper solution for your problem? |
@dzhioev No, we haven't looked into it much since, actually. Let me know if you figure something out! |
Hi there. Update: Update:
It works for me, but you have to create instance of 'translation-element' in every element that uses translation filter. At least we know where 'l' parameter comes from.
To fire signal use something like this:
Where 'this' is any element containing 'translation-element' instance. |
One can use filter syntax to conveniently construct computed properties. For example, I made a json-dump element that uses this construction:
{{object | stringify}}
Where
stringify
is a method on my element which stringifies an input object.However, the stringified representation of
object
depends on more thanobject
(iow, my filter has non-explicit dependencies onobject
's properties).It's normal behavior for the binding not to update when
object
's properties changes, so it would be useful if there was a way to touch, tickle, or kick the binding explicitly when needed.The text was updated successfully, but these errors were encountered: