Skip to content

Should Ember.isEmpty({}) be true? #82

Closed

Description

@nickiaconis

It seems counter-intuitive that Ember.isEmpty({}) returns false. Should it return true instead?

One theoretical hurdle I ran into while writing up the change locally was justifying that the methods which depend on isEmpty should also change. Those methods are isBlank and isPresent.

isBlank is fairly reasonable to justify: an empty object is also blank. Pretty straight-forward.

isPresent is not as easy. If Ember.isEmpty({}) returns true, then Ember.isPresent({}) returns false. This means an empty object is "not present". This seems a little strange at first. I discussed this with a colleague, and we settled on this rational:

An array is an object.
An empty array is both blank and "not present".
Therefore, an empty object is also blank and "not present".

Would you agree?

Activity

  1. rlivsey commented on Aug 12, 2015

    @rlivsey

    Previous discussion indicated that this was because of support for ES3 browsers. Now that Ember 2.0 is dropping support for IE8 then this should be possible.

  2. mmun commented on Aug 13, 2015

    @mmun
    Member

    Any changes these functions will likely break a lot of apps :( It would require mass consensus to change.

  3. stefanpenner commented on Aug 13, 2015

    @stefanpenner
    Member

    Although I agree this would be nice I think this should be user land or addon concern. What defines an empty object is tricky (although I'm sure consensus can be reached) but changes to these core methods would provide dubious value as existing apps do depend on the current semantics.

    I suspect if we where to write isEmpty today it would include a reasonable semantic for this

  4. mmun commented on Aug 13, 2015

    @mmun
    Member

    An addon is a good solution.

  5. Panman82 commented on Sep 14, 2015

    @Panman82

    What about making an addon to "opt-in", then make the switch at 3.0? Then add a depreciation (sigh) about installing the addon to silence the depreciation, when the developer ensures their code will handle the change properly.

  6. stefanpenner commented on Sep 14, 2015

    @stefanpenner
    Member

    @Panman8201 i don't think making the change is worth-while, isEmpty has semantics, changing them is a-bit of a trap. An addon providing some variation of it, sounds like the best path.

    Going to close this as working as intended.

  7. benoror commented on Nov 18, 2016

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions