es5-getter-ember-codemod
es5-getter-ember-codemod copied to clipboard
Support getWithDefault?
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';
@simonihmig I think I spoke too soon. I'm going to mull this one over.
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 What do you think of this? I wasn't sure if it was in scope for this project, would be easy enough to implement.
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.
Ah, agreed. @simonihmig I don't have a lot of experience using getWithDefault
do you know the expected behavior in the current implementation?
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
...