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

Attributes/Converters Issue #174

Closed
thecountofzero opened this issue Nov 26, 2012 · 5 comments
Closed

Attributes/Converters Issue #174

thecountofzero opened this issue Nov 26, 2012 · 5 comments
Assignees
Labels
Milestone

Comments

@thecountofzero
Copy link
Contributor

Using the attributes plugin, I have an attribute of a model that is another type of model. And then an attribute of that second model uses a converter to determine its value.

In my app, it polls the server for fresh data and uses live binding to update the data in view. I noticed that a value that is determined using a converter is wrong after the first go round. It actually seems to be calling the converter twice. The first time with the correct value from the server, and the second time with the converted value. The second (incorrect) value is what is being used.

Please see the following fiddle. To simulate polling, just double click the output frame.

http://jsfiddle.net/thecountofzero/qYdwR/562/

Looking at commits, it seems that the issue was introduced with this commit:

f9896d9

@ghost ghost assigned imjoshdean Nov 26, 2012
@daffl
Copy link
Contributor

daffl commented Dec 18, 2012

@imjoshdean That commit seems to be related to several bugs reported (namely #207 and #208). It would be great if we can figure out how this is supposed to work or fix it for 1.1.4.

@daffl
Copy link
Contributor

daffl commented Jan 11, 2013

Man this is a tough nut. I narrowed it down to __convert being called multiple times when the model is live bound. Still needs some more digigng though.

@moschel
Copy link
Contributor

moschel commented Jan 31, 2013

Tested this against latest locally and its no longer breaking. Tomorrow we'll push out a new 1.1.4 release candidate at http://canjs.us/release/latest/can.jquery.js (this isn't currently actually pushing out every night automated) and this should confirm this issue is fixed.

@moschel
Copy link
Contributor

moschel commented Jan 31, 2013

Actually nevermind what I said above, forgot I had made a local change. Actually these lines in observe.js cause this weird behavior:

if ( self.__convert ) {
  newVal = self.__convert(prop, newVal);
}

__convert is called twice per nested observe, once here and once a few lines down at self._set(prop, newVal). I'm not sure why this was necessary.

f9896d9 introduced this line.

Commenting these lines out fixes this issue and all other can tests still pass. Will talk to @imjoshdean about this tomorrow and get a test in.

@daffl
Copy link
Contributor

daffl commented Feb 5, 2013

Closed via #266.

@daffl daffl closed this as completed Feb 5, 2013
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

4 participants