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

property_set.js won't modify object if value and currentValue is undefined #14270

Closed
makepanic opened this issue Sep 12, 2016 · 5 comments · Fixed by #16417
Closed

property_set.js won't modify object if value and currentValue is undefined #14270

makepanic opened this issue Sep 12, 2016 · 5 comments · Fixed by #16417

Comments

@makepanic
Copy link
Contributor

In newer ember versions, Ember.set(object, 'field', undefined) won't set the field key on an object, because the value is undefined.
It exits earlier here which causes no object modification.

I think this is a regression (introduced in v2.7.0-beta.1), because previously it wouldn't enter that condition, if the value was undefined.

Using a 2.7.0 ember app:
20160912-190913

On discourse:
20160912-200952

A possible way to fix this would to reintroduce the value !== undefined check

@rwjblue
Copy link
Member

rwjblue commented Sep 14, 2016

After reviewing this a bit, I am not certain that Ember.set should actually be changed here. Ember.set isn't about guaranteeing an objects own properties, its about setting the specified property to the given value. If that property already is set to the new value, doing nothing seems like the correct thing to me.

I welcome thoughts from others (cc @krisselden / @stefanpenner), but I don't know that this is a bug...

@stefanpenner
Copy link
Member

Ember.set isn't about guaranteeing an objects own properties, its about setting the specified property to the given value. If that property already is set to the new value, doing nothing seems like the correct thing to me.

i would tend to agree.

@poteto
Copy link

poteto commented Sep 22, 2016

I agree that setting a previously set value to the same value should do nothing.

its about setting the specified property to the given value.

The issue is that let x = {}; Ember.set(x, 'prop', undefined) being a no-op seems inconsistent (and likely a regression given the OP). I would expect x to be set to {prop: undefined}, which is consistent with vanilla object setters

@stefanpenner
Copy link
Member

stefanpenner commented Sep 22, 2016

rwjblue we could set the property and not have it emit a change event. This should align both the ES semantics, and the change tracking semantics.

cc @krisselden

@locks
Copy link
Contributor

locks commented Sep 22, 2016

I opened the file to try and implement stef's suggestion and got intimidated by the code. Should I pursue it, and would it need new tests to be added?

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.

5 participants