-
Notifications
You must be signed in to change notification settings - Fork 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
Some computed methods need non-contextual dependencies, it's not DRY to always list them #3299
Comments
bonus points if this plays nice with behaviors |
I submitted an implementation in #3302 . The implementation is a bit different that the proposal. I discussed this with @sjmiles and he agreed it was "a superior solution". The example in the docs is: <dom-module id="x-computed-with-dependency">
<template>
<span>{{methodName('literal')}}</span>
</template>
<script>
Polymer({
is: 'element-with-dependency',
properties: {
property1: {...},
property2: {...}
},
dependencies: {
methodName: ['property1', 'property2']
},
methodName: function(property1, property2, literal) {}
});
</script>
</dom-module> I have not tested behavior support, but I think that could be implemented fairly easily. Could you elaborate on the specifications for behavior support? E.g. What should happen when behavior and child both declare the same or different dependencies? |
Thanks for looking into this @TimvdLippe!
For my use case I'd want the implementation for As for parent and child declaring same or different dependencies, I haven't thought about that much... Maybe parent just overrides the required dependencies of child? |
@samccone: unless I'm missing something, your pattern can't update the text in the |
@TimvdLippe: to follow current behavior rules, the |
@sjmiles yep your right nm |
@sjmiles @robdodson Behavior support should now be added to the dependencies maps. Please check out this test |
Cool so it looks like this covers this aspect:
Are you also thinking of adding merged depenencies? |
@robdodson Merging of dependencies was already possible, but I forgot to add an explicit check for it. I have updated the test to show merging of dependencies works correctly. |
cool! I'll defer to @sjmiles for approval |
LGTM, will run it by @sorvell and/or @kevinpschaaf for extra care. And ... nice work @TimvdLippe! |
I'm a bit confused why this is called |
@kaste The new behavior of this feature is that annotated computed functions can be updated whenever one of the global arguments is changed. In my eyes, |
Alternate take for Polymer#3299
Take #3358 as a rough concept. I really have no idea if it fulfills all and every requirement. On the other side it's in the same ad-hoc style as the rest of the Polymer source code. Following example:
As you can see As you can see 2: No further configuration is necessary. And although functions which return functions is always a bit meta and an advanced topic, I think any programmer can grab the concept without reading the documentation. I actually tried this before (I wanted to implement the filter function for a dom-repeat in this way), but it wasn't supported (which wasn't documented by the way). So this approach more likely fills a gap in Polymer. |
We had a bunch of discussion on the Polymer team about the pros/cons of the alternate approaches by @TimvdLippe (#3302) and @kaste (#3358). The upshot is that people actually found it strange after thinking about it that observers/computing functions didn't have themselves as an implicit dependency, which is indeed an alternate way to solve the dependency currying problem for the translate use case as @kaste's PR showed. So I think I'll re-open #3358 and make a couple more suggestions there for improvements, and see if we can reach agreement on that approach. |
Alternate take for Polymer#3299
Alternate take for Polymer#3299
Fixed with #3358 |
For posterity, here's an example using the technique we merged (dynamic computing functions) to implement late-bound string translation via a behavior that results in a pretty pleasant end-user experience: http://jsbin.com/lajuci/edit?html,output |
Consider a translation scheme:
The design is that the 'translator` engine is injected by some means (simple property set, e.g.), therefore we must depend on 'translator' to trigger the relevant binding updates. Having to include this static name in every translate binding is a hassle.
One possibility is to add a way to register static dependencies for a computation.
Something like that.
The text was updated successfully, but these errors were encountered: