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

Issue with computedIndirect and two-way bindings #7

Open
fengb opened this issue Dec 1, 2015 · 1 comment · May be fixed by #8
Open

Issue with computedIndirect and two-way bindings #7

fengb opened this issue Dec 1, 2015 · 1 comment · May be fixed by #8

Comments

@fengb
Copy link

fengb commented Dec 1, 2015

When using two-way bindings, a computedIndirect will fire multiple observers:

import Ember from 'ember'
import computedIndirect from 'ember-computed-indirect/utils/indirect'

let Buggy = Ember.Object.extend({
  valuePath: Ember.computed(function () {
    return '_underlying'
  }),

  value: computedIndirect('valuePath'),
  bindedValueBinding: 'value',

  valueObserver: Ember.observer('value', function () {
    console.log('Observe! ' + this.get('value'))
  })
})

> buggy = Buggy.create()
< Object([...])
> buggy.set('bindedValue', 1) // fires two events
< 1
  Observe! 1
  Observe! 1
> buggy.set('value', 2) // fires two events with 1 receiving the wrong value
  Observe! 1
  Observe! 2
< 2

Since components uses bindings, I cannot just convert them into Ember.computed.alias.

@fengb fengb linked a pull request Dec 1, 2015 that will close this issue
@gordonkristan
Copy link
Owner

Yeah, this is very peculiar. It seems it's happening because the setting of value and the setting of _underlying aren't happening atomically. I think we might I might be able to fix that by pausing change observers while modifying the underlying value, but I'm not sure. I'll noodle over this a bit and try to come up with a solution.

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

Successfully merging a pull request may close this issue.

2 participants