Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New API change: Delegate isEmpty() to exists() and begin deprecation of using isEmpty() #722

Merged

Conversation

christemple
Copy link
Contributor

To address the issue whereby isEmpty() being confusing from an API perspective when checking if a node exists().
#705

Includes:

  • addition of exists() function and delegating isEmpty() to exists()
  • deprecation warnings for using isEmpty()
  • updated docs for using exists() and deprecation docs for isEmpty()

@christemple
Copy link
Contributor Author

I've also fixed the gitbook prism plugins version number to the latest that works.

When I tried running the docs it kept failing, which I narrowed down to the latest release of the prism plugin.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems legit 👍

Copy link
Collaborator

@aweary aweary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as well! 👍

@ljharb
Copy link
Member

ljharb commented Dec 11, 2016

(would be nice to rebase down to a single commit)

@christemple christemple force-pushed the change_isempty_to_exists_and_alias branch from fc3c98d to 56a62fe Compare December 11, 2016 20:59
@christemple
Copy link
Contributor Author

@ljharb done 👍

*
* @returns {boolean}
*/
isEmpty() {
return this.length === 0;
// eslint-disable-next-line no-console
console.warn('Deprecated method isEmpty() called, use exists() instead.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth ensuring we only log this once? I imagine anyone using isEmpty getting 100s of these warnings..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice to prefix this with Enzyme:: just so people know where the warning is coming from.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sounds like a good idea, I'll update this tomorrow, thanks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I'm wondering if we should hold off on the deprecation notice in-code for now, until we've been able to make PRs into things like chai-enzyme and others - ie, give a whole release before adding the warning message in?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ljharb up to you. But I always just put deprecation warnings in on minor versions and pull them out in next major versions. I think react adds deprecations in majors only?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blainekasten I definitely think prefixing with Enzyme:: makes sense, however after thinking more about it, I'm not so sure about logging it only once.

If someone uses isEmpty() a lot isn't it better to make noise to encourage people to make the switch sooner rather than later so the tech debts lifespan is short?

The noise was very helpful for me, after switching off mocha --reporter dot, to identify and locate specs using isEmpty so that I could update them, as isEmpty() is the equivalent of !exists() it wasn't a matter of doing a global search and replace on the specs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how we'd "only log once" - store a global? what's "once" - if i'm using --watch with my tests, should only the first run log it?

I think if it logs, it has to log every time.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how we'd "only log once" - store a global?

React uses a scoped flag to only log warnings once, but I think in our case it makes the most sense to just log every time. Test output can be rather verbose, making a single warning potentially hard to distinguish. isEmpty isn't likely used with extreme frequency in the average test suite either, so in most cases we're probably not going to be outputting too much noise.

Also, in regards to versioning: semver specifies that deprecation warnings should go in minor releases so I'm 👍 with that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point @ljharb. --watch mode defeats the ability to store a global. Logging every time seems like the best option for us. Good discussion guys!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just done the update to prefix Enzyme:: in the warning

@christemple christemple force-pushed the change_isempty_to_exists_and_alias branch from 56a62fe to 98d7961 Compare December 13, 2016 16:38
@blainekasten
Copy link
Contributor

lgtm! Thanks

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

Successfully merging this pull request may close these issues.

4 participants