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

[0.8] Multiple computed properties call same method #1242

Closed
ssorallen opened this issue Mar 2, 2015 · 2 comments
Closed

[0.8] Multiple computed properties call same method #1242

ssorallen opened this issue Mar 2, 2015 · 2 comments
Labels

Comments

@ssorallen
Copy link
Contributor

When pointing multiple computed properties to the same method but with different arguments, the output is unexpected.

https://gist.github.com/ssorallen/07337da2bbfb4929333a

<link rel="import" href="../polymer/polymer.html">

<dom-module id="multi-compute">

  <template>
    <div class-name="[[first]]"></div>
    <div class-name="[[second]]"></div>
  </template>

</dom-module>

<script>
  Polymer({
    is: 'multi-compute',

    computed: {
      first: 'computeClassName(foo)',
      second: 'computeClassName(bar)'
    },

    configure: function() {
      return {
        bar: 'hola',
        foo: 'bonjour'
      };
    },

    computeClassName: function(c) {
      return c;
    }
  })
</script>

Expected output when using the multi-compute element:

<multi-compute>
  <div class"bonjour"></div>
  <div class="hola"></div>
</multi-compute>

Actual output:

<multi-compute>
  <div class"bonjour"></div>
  <div></div>
</multi-compute>
@ssorallen ssorallen added the 0.8 label Mar 2, 2015
@ssorallen
Copy link
Contributor Author

The method strings constructed by the computed property code pass the same value to debounce. In the example they end up containing:

this.debounce('_computeClassName', function() { ... })

Since they pass the same value as the task name, debounce does its job and calls the function only once because the calls happen within a short period of time.

Computed properties need to ensure the task names they pass to debounce are unique among all computed properties of a model.

ssorallen pushed a commit that referenced this issue Mar 2, 2015
If multiple computed properties call the same method but with different
arguments, calls to the method are debounced because they pass the same
value as the task name. Rather than name the task only the method name,
use the full expression to let the developer ensure uniqueness.

Example:

```js
computed: {
  foo: 'computeClassName(bar)',
  baz: 'computeClassName(xyz)'
}
```

Currently they both create property effects wrapped in debounce calls
with task names of '_computeClassName':

```js
this.debounce('_computeClassName', function() { ... })
this.debounce('_computeClassName', function() { ... })
```

By passing the full expression rather than the method name, they result
in unique debounce task names:

```js
this.debounce('_computeClassName(bar)', function() { ... })
this.debounce('_computeClassName(xyz)', function() { ... })
```

Fixes #1242
@sorvell sorvell added 0.8 and removed 0.8 labels Mar 5, 2015
@sorvell
Copy link
Contributor

sorvell commented Mar 5, 2015

Closed via #1243

@sorvell sorvell closed this as completed Mar 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants