-
Notifications
You must be signed in to change notification settings - Fork 5
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
Move values
to options
#10
base: master
Are you sure you want to change the base?
Conversation
Hey ! I understand the reflexion. I'm thinking I'm gonna use this but only after publishing your other PRs with the correct semver bumps. This one is obviously a breaking change. |
function Envie (description, options = {}) { | ||
if (!(this instanceof Envie)) return new Envie(description, options) | ||
const { | ||
values = process.env, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this does what needs to be done. Doesn't this assign options.values
to process.env
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a pretty normal way to deal with default values nowadays since destructuring is becoming the norm. This creates the variable values
from options.values
with the fallback of process.env
.
From MDN web docs:
var {a = 10, b = 5} = {a: 3};
console.log(a); // 3
console.log(b); // 5
You can see that the tests pass too, so it definitely works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, I mistook it for values: process.env
if (!(this instanceof Envie)) return new Envie(description, options) | ||
const { | ||
values = process.env, | ||
noDefaults = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, I'm not sure what this does. Even if it works I think i'd prefer a less cool but clearer approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand it's confusing if it's the first time you read it - but it's clearer than
const values = typeof options.values === 'undefined' ? options.values : process.env;
const noDefaults = typeof options.noDefaults === 'undefined' ? false : options.noDefaults;
.. or to reassign options arg that you can see in a lot of old jQuery-plugins, etc
options = Object.assign({}, {
noDefaults: false,
values: process.env,
}, options || {});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I usually do
const values = options.values || process.env
which I find rather short and self-explanatory. But I mostly find it more used to!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This:
const values = options.values || process.env
const noDefaults = options.noDefaults || true
Won't work for booleans.. e.g. if we'd implement #8 it'd always be true
, that's why the typeof
is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you know how deconstructuring works (been around since node 6) the pattern I do in this PR is self-explanatory as well. Get with the times! :D
It's a breaking change indeed, so it'd need a Also, can you reflect on #8 and leave a comment what you think? Also breaking, could go in the same major if you agree. |
Closes #7