Skip to content

Instantly share code, notes, and snippets.

@ptgamr
Last active July 21, 2016 12:25
Show Gist options
  • Save ptgamr/b5a3d34abb873d3e99cfc0e2c2f202e6 to your computer and use it in GitHub Desktop.
Save ptgamr/b5a3d34abb873d3e99cfc0e2c2f202e6 to your computer and use it in GitHub Desktop.
Ember get-with-default
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;
});
@btecu
Copy link

btecu commented Jul 21, 2016

Your return could be simplified:
return Ember.getWithDefault(obj, path, defaultValue);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment