ember.js: Ember.isEmpty({}) returns false

Currently Ember.isEmpty returns false if I pass in an empty object when I would expect it to return true. This feels like a gap in the functionality.

@taras suggested using Ember.keys({}).length === 0 and while this certainly works it doesn’t feel intuitive when you have Ember.isEmpty available.

It’s trivial to implement - I’d be glad to submit a PR if it’s agreed that it is indeed a gap.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 2
  • Comments: 25 (11 by maintainers)

Most upvoted comments

I don’t think so. And it should have been IMO. It does not make sense that Ember.isEmpty({}) is false.

Was this revisited in 2.0?

Bump, makes no sense that an empty object isn’t empty.

Almost certainly Ember.{isEmpty,isBlank,isNone,isPresent} should be deprecated. They don’t really add value over the normal JS that you would write in each case, and they generally have negative cognitive impact on the code in question…

Seems silly to dip into jQuery for this check - can we revisit this issue now that we’re 3.0?

Also this is directly present in JQuery – https://api.jquery.com/jQuery.isEmptyObject/

Ember.keys({}).length === 0 could be added to Em.isEmpty for testing objects.

@ashish2199 the current proposal is to deprecate the APIs, not change them: https://github.com/emberjs/rfcs/pull/334.

@jfschaff @marclundgren Old comment, I referenced the description on the jsdoc that didn’t mention checking for an empty object. Currently lives here:

https://github.com/emberjs/ember.js/blob/master/packages/%40ember/-internals/metal/lib/is_empty.ts#L6-L7

Not to say that I didn’t expect the method to check an empty object as well, just saying that there wasn’t such a claim in the first place.

(updated original comment)

@rwjblue Getting some feedback that these methods will still be bundled in Ember core. How should we handle the deprecation side of things for these util methods?

We’ve been using lodash _.isEmpty(), _.isNil(), etc. which actually work correctly