Skip to content

Add more information about #remove method#273

Closed
Bartuz wants to merge 4 commits intojs-cookie:masterfrom
Bartuz:patch-1
Closed

Add more information about #remove method#273
Bartuz wants to merge 4 commits intojs-cookie:masterfrom
Bartuz:patch-1

Conversation

@Bartuz
Copy link
Copy Markdown
Contributor

@Bartuz Bartuz commented Oct 3, 2016

It took me few minutes to find it on my own. Hope to save time of other developers!

Just a useful info about remove method :)

Bartuz added 3 commits October 3, 2016 11:16
It took me few minutes to find it on my own. Hope to save time of other developers! 

Just a useful info about remove method :)
Comment thread README.md
Cookies.remove('name');
```

Please notice that removing unexisting cookie does not raise any exception nor return any value
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That doesn't mean the cookie doesn't exist, that means the cookie is not accessible. It is impossible to verify if the cookie exist or not.

We have discussed this in the past, see carhartl/jquery-cookie#164 (comment).

Comment thread README.md Outdated
```javascript
var whatWasTheValue = Cookies.remove('nothing');
if (whatWasTheValue === undefined) {
console.log("I will be excuted");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Typo

Comment thread README.md Outdated
Please notice that removing unexisting cookie does not raise any exception nor return any value

```javascript
var whatWasTheValue = Cookies.remove('nothing');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can name the variable consistently throughout the docs

Comment thread README.md
if (whatWasTheValue === undefined) {
console.log("I will be excuted");
} else {
console.log("I will never be executed");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe a comment instead of console.log?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I used console.log instead of comments because I wanted to emphasize that this line will be executed (i.e. there isn't unhandled exception which stops javascript thread [tbh I don't know if it happens in javascript but I'm sure some other Javascript newbies are also using this library :) IMHO it's not a big deal to make a bit longer code snipper but make it understable by broader audience])

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I mainly started this #remove research because comment here:

Cookies.remove('name'); // fail!

didn't make me sure enough if fail means exception, undefined or something else.

In Ruby fails means throw exception, so I needed to double check this one 😆

Copy link
Copy Markdown
Member

@FagnerMartinsBrack FagnerMartinsBrack Oct 4, 2016

Choose a reason for hiding this comment

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

Makes total sense your // fail! example.

Would this work then:

Cookies.remove('name'); // doesn't work

Copy link
Copy Markdown
Member

@FagnerMartinsBrack FagnerMartinsBrack Oct 4, 2016

Choose a reason for hiding this comment

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

Or maybe:

Cookies.remove('name'); // doesn't do anything

Or:

Cookies.remove('name'); // silently fails

Or:

Cookies.remove('name'); // noop

The last one can have accessibility problems because not everyone knows what the noop concept means.

The reason why I am suggesting those approaches is because it might be interesting to focus on the least amount of text that fixes any confusion. The README is in a state where any new addition will increase the friction because there will be more content, so it might be worth putting some effort to not add new paragraphs unless essential.

Since you just started with the library you don't have the maintainers bias on the README because we already know how the API works and we can't make the docs better for that reason. Your feedback is really really valuable! Thanks for helping out!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's really nice you appreciate my voice here, thanks :)

I like your approach to keep guides as short as possible but IMHO your new comments may confuse people even more than fail.

The problem is that current fail comment is used for the first time in context of "valid path of current page" so even adding super descriptive comment there is not intuitive enough to communicate that even removing Cookie with proper "path" argument also "fails"

I would just add block that every .remove call ends up with undefined, successful or not

Cookies.remove('name'); // returns undefined
Cookies.remove('nothing'); // also returns undefined

Copy link
Copy Markdown
Member

@FagnerMartinsBrack FagnerMartinsBrack Oct 5, 2016

Choose a reason for hiding this comment

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

I understand. What about something like this then:

Delete a cookie that is visible on the current page:

Cookies.set('name', 'value', { path: '' });
Cookies.remove('name'); // doesn't remove the cookie
Cookies.remove('name', { path: '' }); // removes the cookie

We can then consistently use "visible" instead of "valid" where we are talking about the cookie visibility based on the attributes, replacing throughout the docs.

Unfortunately, we can't document that Cookies.remove() returns undefined because that's not a supported behavior. It is actually void and returns nothing.

What do you think?

@FagnerMartinsBrack
Copy link
Copy Markdown
Member

Maybe we can have a generic documentation saying that it will never throw an exception except for the cases it will (like the getJSON() when it misses global JSON API, for example)?

@FagnerMartinsBrack
Copy link
Copy Markdown
Member

Maybe we can have a generic documentation saying that it will never throw an exception except for the cases it will (like the getJSON() when it misses global JSON API, for example)?

It seems my previous comment was wrong. We don't throw any exception when window.JSON is not present since the code is in a try/catch block.

Actually, it looks like we never throw any exception for documented functionality, maybe we can make that clear in the docs instead of just documenting a single API?

@Bartuz Do you still want to work on this?

@FagnerMartinsBrack FagnerMartinsBrack added this to the v2.1.4 milestone Oct 15, 2016
@FagnerMartinsBrack
Copy link
Copy Markdown
Member

Ping @Bartuz, do you still want to work on this PR?

@FagnerMartinsBrack FagnerMartinsBrack dismissed their stale review January 9, 2017 10:51

Due to the lack of feedback from the OP I'll land with a few modifications

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants