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

Code styling #37

Open
wingleung opened this issue Nov 29, 2019 · 1 comment
Open

Code styling #37

wingleung opened this issue Nov 29, 2019 · 1 comment

Comments

@wingleung
Copy link
Contributor

wingleung commented Nov 29, 2019

As of now, the code is very verbose and easy to read but I'm wondering if we can optimize readability by tweaking some code styles and namings to prevent double negatives.

For example, the following code...

let unsupported;

const useSaveData = (initialSaveDataStatus = null) => {
  if ('connection' in navigator && 'saveData' in navigator.connection) {
    unsupported = false;
  } else {
    unsupported = true;
  }

  return {
    unsupported,
    saveData: unsupported
      ? initialSaveDataStatus
      : navigator.connection.saveData === true
  };
};

export { useSaveData };

could become...

const useSaveData = (initialSaveDataStatus = null) => {
  const supported = ('connection' in navigator && 'saveData' in navigator.connection)

  return {
    unsupported: !supported,
    saveData: supported
		? navigator.connection.saveData === true
		: initialSaveDataStatus
  };
};

export { useSaveData };

maybe even use a supported property in the return value, I'm not sure if it's deliberate that we use negative naming for this.

@anton-karlovskiy
Copy link
Contributor

@wingleung cc @addyosmani

I think we can use supported. At the beginning I named like so, but found that it could be better if we used supported.

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

No branches or pull requests

2 participants