Js-cookie: Why is the api function responsible for read and write?

Created on 16 Mar 2018  路  5Comments  路  Source: js-cookie/js-cookie

Why is the api function responsible for read and write?
api function any intention to change responsibility depending on the number of arguments?

All 5 comments

For the Public API, it makes no difference, you still have read and write methods. Internally, it uses the same function for the purpose of reducing the byte size and allow the code to be GZipped around the 900 bytes target, as stated in the README as a feature.

This is a compromise between "Clean Code"/"Clean Architecture"/"SOLID" vs "100% code coverage + downloadable bytes". Ideally, we would want "Clean Code"/"Clean Architecture"/"SOLID" + "100% coverage", unfortunately, we would have to trade "downloadable byte size", so we're making a compromise.

There's no silver bullet.

Given this is a very small and focused project that serves a single purpose (create some sense to the document.cookie API), and is used in a lot of websites, we believe it's a fair compromise to make.

It is also due to heritage of once being _jquery-cookie_. In jQuery back then it was a common pattern to have this kind of overload for read + write operations.

An interesting side-effect of this is https://github.com/js-cookie/js-cookie/issues/417.

I don't think there's anything we can act on here. Closing then...

@FagnerMartinsBrack

Thank you for answering.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

edwardfhsiao picture edwardfhsiao  路  8Comments

junglized picture junglized  路  5Comments

oninross picture oninross  路  9Comments

migsyboy picture migsyboy  路  7Comments

tom-korec picture tom-korec  路  3Comments