You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@workmanw my usecase isn't null checking. I was passing an object to store.find and had a need to remove a specific property on the object if present and then check to see if the object had other properties or if it was empty.
...
if(typeofquery.procedure!=='undefined'){varproc=query.procedure;varhttpRequestType='GET';deletequery.procedure;// check to see if there are additional query params// Currently Ember.isEmpty(query) will always return false even if query has no additional propertiesif(!Ember.isEmpty(query)){httpRequestType='POST';}}
...
Ember.isNone({}) returns false which is correct because the object isn't null - it's empty.
This was decided because we couldn't guarentee the same results across all our browsers. As es3 browsers have no concept of user defined non enumerable methods. At the point in time we where we drop them we could revisit this.
With 2.0 dropping support for IE 8 could we consider fixing this behavior to be true on {}? That would seem more consistent with the behavior for [] and 2.0 would be a good occasion to introduce an API breaking change.
Bump, makes no sense that an empty object isn't empty.
Reacted by Hassan McKusick, Lucas Øverland, Nolan Evans, Mark Kurkowski, Mariusz Hausenplas, Nanda Kumar, Mark Beavis, Josh Rosen, Ashish Padalkar and Nabeel Zafar
We can likely revisit this in 2.0 which drops support for IE8, so now there is a concept of enumerable vs non enumerable properties across all our target platforms.
In-fact aspects of ember already rely on this concept. {{each-in}
If someone is interested in championing and RFC we may be able to re-open things thought.
Reacted by Jeyakumar, Ernesto García, BlueRaja, Rowan Krishnan, Bose Jankulovski, cecemel, Mehmet Akif Ersoy, nschikora, Daniel Nelson, Justin Smestad and 3 more
I don't think so. And it should have been IMO. It does not make sense that Ember.isEmpty({}) is false.
Reacted by Cory Loken, Jeremy Ward, Carlos Solares, Nathaniel Furniss, Steve Rhoades, Hassan McKusick, Matt Gardner, BlueRaja, nschikora, Daniel Nelson and 8 more
Anybody coming across this - looks like in a 2015 rfc, it was decided that returning true for {} would have desired unintended side effects.
If that is still the current thought process and the addon is a path forward, I would be happy to put that out there. However, it's super simple to implement ourselves, so perhaps that is why nobody has done so ¯_(ツ)_/¯
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...
Reacted by Bill Brower, Scott Newcomer, Ernesto García, Dan Freeman, Jimmeh, Gino, Josh Rosen and Ashish Padalkar
@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?
Activity
taras commentedon Sep 4, 2014
Ember.keys({}).length === 0could be added to Em.isEmpty for testing objects.workmanw commentedon Sep 4, 2014
I think there is a distinction betweenEmber.isEmptyandEmber.isNone. If you're looking for null checking, you should useEmber.isNone.Completely misread. Sorry about that.
ultimatemonty commentedon Sep 4, 2014
@workmanw my usecase isn't null checking. I was passing an object to
store.findand had a need to remove a specific property on the object if present and then check to see if the object had other properties or if it was empty.Ember.isNone({})returns false which is correct because the object isn't null - it's empty.gtsop commentedon Sep 7, 2014
isEmpty is not meant to check for empty objects:
https://github.com/emberjs/ember.js/blob/master/packages/ember-metal/lib/is_empty.js#L6-L7https://github.com/emberjs/ember.js/blob/master/packages/%40ember/-internals/metal/lib/is_empty.ts#L6-L7
stefanpenner commentedon Sep 7, 2014
This was decided because we couldn't guarentee the same results across all our browsers. As es3 browsers have no concept of user defined non enumerable methods. At the point in time we where we drop them we could revisit this.
ultimatemonty commentedon Sep 7, 2014
thanks @stefanpenner will close for now and use @taras suggested method.
ronco commentedon May 21, 2015
With 2.0 dropping support for IE 8 could we consider fixing this behavior to be true on
{}? That would seem more consistent with the behavior for[]and 2.0 would be a good occasion to introduce an API breaking change.BlueRaja commentedon Jun 10, 2015
Bump, makes no sense that an empty object isn't empty.
timini commentedon Jul 2, 2015
Confusing.
stefanpenner commentedon Jul 2, 2015
We can likely revisit this in 2.0 which drops support for IE8, so now there is a concept of enumerable vs non enumerable properties across all our target platforms.
In-fact aspects of ember already rely on this concept.
{{each-in}If someone is interested in championing and RFC we may be able to re-open things thought.
BillBrower commentedon Feb 1, 2017
Was this revisited in 2.0?
gnapse commentedon Feb 8, 2017
I don't think so. And it should have been IMO. It does not make sense that
Ember.isEmpty({})is false.akshayrawat commentedon Mar 10, 2017
Also this is directly present in JQuery – https://api.jquery.com/jQuery.isEmptyObject/
joshkg commentedon Mar 21, 2018
Seems silly to dip into jQuery for this check - can we revisit this issue now that we're 3.0?
snewcomer commentedon May 22, 2018
Anybody coming across this - looks like in a 2015 rfc, it was decided that returning true for
{}would have desired unintended side effects.If that is still the current thought process and the addon is a path forward, I would be happy to put that out there. However, it's super simple to implement ourselves, so perhaps that is why nobody has done so ¯_(ツ)_/¯
emberjs/rfcs#82
rwjblue commentedon May 22, 2018
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...BlueRaja commentedon May 22, 2018
We've been using lodash
_.isEmpty(),_.isNil(), etc. which actually work correctlysnewcomer commentedon May 22, 2018
I agree. Should I/we put together an RFC? And potentially extracted to an addon as well (for those that gratuitously used them)?
locks commentedon May 22, 2018
@snewcomer forge ahead :) emberjs/rfcs#333
snewcomer commentedon Jun 2, 2018
@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?
jfschaff commentedon Jun 17, 2019
The function name has just been poorly chosen... IsEmpty should tell you yes when given... an empty "set"...
marclundgren commentedon Oct 8, 2019
404
gtsop commentedon Oct 31, 2019
@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)
ashish2199 commentedon Oct 5, 2020
Where are we on this? Will this ever be incorporated?
locks commentedon Oct 5, 2020
@ashish2199 the current proposal is to deprecate the APIs, not change them: emberjs/rfcs#334.