Skip to content

Code styling #37

Description

@wingleung

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions