Skip to content
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

processing bindings in a specific order #368

Closed
sigmundch opened this issue Dec 11, 2013 · 4 comments
Closed

processing bindings in a specific order #368

sigmundch opened this issue Dec 11, 2013 · 4 comments

Comments

@sigmundch
Copy link

Today, template-binding processes attribute bindings in the order that are returned by the browser (code). This may be the lexical order or something else (FF and Chrome are not consistent here, for example).

Normally this is not an issue, but when using 'on-foo' handlers in polymer, it becomes more obvious when some events are fired in a different order than the one specified in the template code.

Here is a concrete example:

<script src="platform/platform.js"></script>
<link rel="import" href="polymer/polymer.html">

<polymer-element name="x-test">
<template>
  <input value="{{current}}" on-input="{{handler}}">
</template>
</polymer-element>

<x-test></x-test>

<script>
Polymer('x-test', {
    current: 'abc',
    currentChanged: function() {
      console.log('0: ' + this.current);
    },
    handler: function() {
      console.log('1: ' + this.current);
    }
});
</script>

If you type a letter at the end of the textbox, you'll see the following printed in Chrome:

0: abcd
1: abcd

But the following printed in FF:

1: abc
0: abcd

This causes the odd effect that the handler is invoked before the bindings are propagated.

Could/should polymer or template-binding do something special here?

@dfreedm
Copy link
Member

dfreedm commented Dec 17, 2013

Thanks for the detailed test case!

I think we'll have to look at this with the data binding braintrust (@rafaelw @ajklein @sorvell).

@sorvell
Copy link
Contributor

sorvell commented Dec 17, 2013

The mental model here is that bindings are resolved asynchronously and there is no guarantee of resolution ordering. If two bindings depend on each other than this dependency must be explicit.

In this exact case, the value binding to input is the best way to see the live value of the input.

If the use case here is more complicated, we'll need more details to help recommend a proper course.

@rafaelw
Copy link
Contributor

rafaelw commented Dec 17, 2013

Yup. The issue is what order the attributes are returned by the user agent. This is another good reason to let event binding be a concern of NodeBind. If that's the case, we can ensure the ordering of (1) event handlers (2) observer change callbacks.

@joo
Copy link

joo commented Dec 17, 2013

This issue can be solved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants