-
Notifications
You must be signed in to change notification settings - Fork 2k
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] accidental shared state in configure value? #1269
Comments
If the initial value is a primitive like a Number, a Boolean, or a String, it is okay to set it as the value. If the initial value is an Object you need to provide a function that returns the initial: value: function() {
return {
name: {
first: 'James',
last: 'Cook',
},
counter: 1
};
} |
Wouldn't it make more sense to automatically also copy non primitive types if no function is provided? It would still be possible to write a function when a copy is not sufficient. Just creating an avoidable shared state seems to be not really convenient. |
A shallow copy works in the case you gave, but consider more complex data structures that are not just simple JavaScript objects. This is a case better left to the developer because he or she has more knowledge about the data structure than the framework can possibly infer. |
I understand the idea - but I didn't want to remove the function. I just think it's quite surprising that when no function is provided a shared state is created. If using a default value for an object really requires to always write a function then without such a function, I think no default should be copied. |
This can be a little confusing, but it's also fundamental language functionality. We can't know what's appropriate since there are cases when it's desirable for the object to actually be shared on the prototype. For these reasons, we've elected to allow the user to give Polymer explicit information by providing a function that can generate the default property value. |
I have an element with a property of type Object with a default value like
When using that element all instances share the same "user" object.
I think the reason for this is
https://github.com/Polymer/polymer/blob/0.8-preview/src/features/standard/configure.html#L75
After I changed that line to
the shared state didn't happen any longer.
The text was updated successfully, but these errors were encountered: