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

Add .if_exists()/.if_visible() (implements #266) #267

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

aexaey
Copy link

@aexaey aexaey commented Feb 28, 2017

No description provided.

@awlayton
Copy link
Collaborator

awlayton commented Mar 7, 2017

I'm not sure how I feel about these functions. They feel unnecessary to me.

If other people want them I might pull them in. Do you have an opinion @johntitus?

Also, the underscores in the name irk me, the do not match any of the other function names.

@aexaey
Copy link
Author

aexaey commented Mar 7, 2017

Regarding underscores - would this sort of syntax be more palatable?

.visible('#foo')
.if(function() {
        ...

i.e. add new if action that does the same as then, but conditionally.

@awlayton
Copy link
Collaborator

awlayton commented Mar 7, 2017

I would have just made them .ifExists and .ifVisible

@aexaey
Copy link
Author

aexaey commented Mar 7, 2017

Oh, I see. Cool. I've changed PR to use headlessCamelCase.

@johntitus
Copy link
Owner

Seems useful but I too hesitate to go too far down this sort of rabbit hole. I lean towards accepting this PR (and thanks for making it @aexaey) if tests are added.

@aexaey
Copy link
Author

aexaey commented Mar 8, 2017

Thanks @johntitus , I've added tests and bare-bones descriptions to Readme.md.
Let me know if you'd like this PR squashed into a single commit.

Copy link
Collaborator

@awlayton awlayton left a comment

Choose a reason for hiding this comment

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

Thanks again for contributing. I found some things.

*/
exports.ifExists = function(selector, fn) {
debug('.ifExists()', selector);
return this.count(selector).then(function(count) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should just use the existing .exists() action rather than re-implementing it.

*/
exports.ifVisible = function(selector, fn) {
debug('.ifVisible()', selector);
return this
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again, you should utilize the existing .visible() action.

return this.count(selector).then(function(count) {
if (count > 0) {
return fn();
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please make the indentation consistent, as I am neurotic about that.

debug('.ifExists()', selector);
return this.count(selector).then(function(count) {
if (count > 0) {
return fn();
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should pass the resolution value of the previous Promise to fn.

For example

...
    .return('foobar')
    .ifExists('selectorThatExists', function(res) {
        console.log(res); // Should log 'foobar'
    })

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

Successfully merging this pull request may close these issues.

3 participants