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

Don't modify passed options #13

Open
moll opened this issue Feb 8, 2015 · 4 comments
Open

Don't modify passed options #13

moll opened this issue Feb 8, 2015 · 4 comments
Labels

Comments

@moll
Copy link

moll commented Feb 8, 2015

Themis modifies the passed-in options object. That causes unexpected stuff when that object is shared between invocations. E.g. when given immutable options:

TypeError: Can't add property file, object is not extensible
  at Object.Utils.defaults (/Users/user/node_modules/themis/src/themis.js:123:50)
@kumarharsh
Copy link
Member

This is an expected behaviour, and follows the convention. If you want to maintain the object, pass it as a copy to themis.
See lodash#_.defaults

@moll
Copy link
Author

moll commented Aug 1, 2015

Which convention? Modifying passed in objects unless they're clearly defined as output variables is a cardinal sin everywhere, regardless of language. Any random book on good API design talks about that. ;-)

@atrniv
Copy link
Member

atrniv commented Aug 1, 2015

@kumarharsh means the convention for applying defaults is followed, however I think @moll has a point.
You don't expect your options object to be modified.

@moll I agree, there wasn't enough thought put in during the design phase while writing the initial code. Themis has largely been used as an internal tool and I've not had the time to make and document improvements in the last few months. However I'm currently working on a new version of themis which will have a much cleaner code base and one that will not mutate schema or options objects. Object mutations will occur only if you allow Themis to apply defaults.

In the meanwhile if you could open a pull request to fix this issue I would be happy to merge it.
I believe one possible solution is writing a Utils.extend function and using that to extend a defaults object with the passed in options.

@atrniv atrniv reopened this Aug 1, 2015
@atrniv atrniv added bug and removed wontfix labels Aug 1, 2015
@kumarharsh
Copy link
Member

@moll I meant to say that it was in line with what other popular libraries, like lodash, have been doing.

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

No branches or pull requests

3 participants