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

Support getWithDefault? #1

Open
simonihmig opened this issue Feb 7, 2018 · 6 comments
Open

Support getWithDefault? #1

simonihmig opened this issue Feb 7, 2018 · 6 comments
Labels
enhancement New feature or request

Comments

@simonihmig
Copy link
Contributor

First of all, this is really nice! :)

As you asked for feedback, how about supporting getWithDefault()?

// Before
person.getWithDefault('lastName', 'Doe');

// After
person.lastName !== undefined ? person.lastName : 'Doe';
@rondale-sc
Copy link
Collaborator

@simonihmig I think I spoke too soon. I'm going to mull this one over.

@simonihmig
Copy link
Contributor Author

My though was that .getWithDefault() is basically syntactic sugar for .get(), so if you want to get rid of .get() completely, you should also remove getWithDefault(). Same with getProperties(), which you already have covered nicely.

@Turbo87 Turbo87 added the enhancement New feature or request label Mar 22, 2018
@rondale-sc
Copy link
Collaborator

@Turbo87 What do you think of this? I wasn't sure if it was in scope for this project, would be easy enough to implement.

@Turbo87
Copy link
Collaborator

Turbo87 commented Mar 22, 2018

Should be possible, but I'm unclear about how getWithDefault() determines when to use the default value. Does it use the default value for everything that is falsey? or only for undefined? or something totally different? This has the potential to change behavior which we should try to avoid if possible.

@rondale-sc
Copy link
Collaborator

Ah, agreed. @simonihmig I don't have a lot of experience using getWithDefault do you know the expected behavior in the current implementation?

@simonihmig
Copy link
Contributor Author

I wasn't sure about that, until I quickly looked it up: 😜
https://github.com/emberjs/ember.js/blob/dd933614629d1ac5cf118181661392faabb53641/packages/ember-metal/lib/property_get.js#L177-L182

So a strict equal check for undefined...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants