Last active
July 21, 2016 12:25
-
-
Save ptgamr/b5a3d34abb873d3e99cfc0e2c2f202e6 to your computer and use it in GitHub Desktop.
Ember get-with-default
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from "ember"; | |
export default Ember.Helper.helper(function([obj, path, defaultValue]){ | |
if (Ember.isEmpty(path)) { | |
// or throw an error | |
return; | |
} | |
return obj ? Ember.get(obj, path) || defaultValue : defaultValue; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your return could be simplified:
return Ember.getWithDefault(obj, path, defaultValue);