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

Move values to options #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

KATT
Copy link
Contributor

@KATT KATT commented Jun 13, 2018

Closes #7

@coveralls
Copy link

coveralls commented Jun 13, 2018

Coverage Status

Coverage increased (+0.7%) to 100.0% when pulling 6875b6e on KATT:feature/move-values-to-options into b638df2 on Floby:master.

@Floby
Copy link
Owner

Floby commented Jul 11, 2018

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,
Copy link
Owner

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 ?

Copy link
Contributor Author

@KATT KATT Jul 11, 2018

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.

Copy link
Owner

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
Copy link
Owner

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

Copy link
Contributor Author

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 || {});

Copy link
Owner

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!

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

@KATT
Copy link
Contributor Author

KATT commented Jul 11, 2018

It's a breaking change indeed, so it'd need a major bump.

Also, can you reflect on #8 and leave a comment what you think? Also breaking, could go in the same major if you agree.

@Floby Floby mentioned this pull request Jul 11, 2018
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.

None yet

3 participants