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

Binding to an Observe.compute value is broken #372

Closed
wants to merge 1 commit into from
Closed

Conversation

ccummings
Copy link
Contributor

var person = new can.Observe({
    name: 'Jeeves'
});
var name = person.compute('name');
name.bind('change', function(ev, newVal, oldVal) {
    ...
});
name('Alfred');

The change handler in this example will be called twice. Once with the newVal as Alfred and a second time with newVal as the Observe instance (person).

Here's how this happens:

When the name compute is updated, we end up in compute.js and run the set function which is defined here in observe.js. This calls attr which fires a change event with newVal === 'Alfred'.

setVal is now the Observe instance since attr returns the Observe, so when the execution reaches here, a change event is triggered with newVal set to the Observe instance.

This code was added by @justinbmeyer here to extend can.compute.

@ccummings
Copy link
Contributor Author

Seems this issue is a bit more serious than I first thought. It's not just a duplicate event that is emitted, the compute you get from Observe.compute will have its value changed to the Observe If you bind to the change event. So in the example above adding this:

setTimeout(function() {
    console.log(name())
}, 2000);

Would log the Observe because the compute has been set to the Observe instance.

@justinbmeyer
Copy link
Contributor

Can you add a test and I will fix it tonight.

Sent from my iPhone

On Apr 30, 2013, at 11:24 AM, Curtis Cummings notifications@github.com wrote:

Seems this issue is a bit more serious than I first thought. It's not just a duplicate event that is emitted, the compute you get from Observe.compute will have its value changed to the Observe If you bind to the change event. So in the example above adding this:

setTimeout(function() {
console.log(name())
}, 2000);
Would log the Observe because the compute has been set to the Observe instance.


Reply to this email directly or view it on GitHub.

@justinbmeyer
Copy link
Contributor

The test seems to pass for me.

matthewp added a commit that referenced this pull request Oct 28, 2015
This fixes our can/view/stache/system plugin to normalize the dynamic
module names before adding them to System.bundle. This is needed because
steal-tools normalizes the bundle names and if the names are relative it
will throw an exception. Fixes #372
matthewp added a commit that referenced this pull request Oct 28, 2015
This fixes our can/view/stache/system plugin to normalize the dynamic
module names before adding them to System.bundle. This is needed because
steal-tools normalizes the bundle names and if the names are relative it
will throw an exception. Fixes #372
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 this pull request may close these issues.

None yet

2 participants