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

feat: reduce props API surface area #162

Merged
merged 12 commits into from
Aug 13, 2018
Merged

Conversation

frederickfogerty
Copy link
Contributor

@frederickfogerty frederickfogerty commented Jul 30, 2018

BREAKING CHANGE: faces is no longer set by default.

Deprecations (supported until v9):

  • props auto, crop, entropy, faces, and fit (have been rolled into imgixParams)
  • customParams (renamed to imgixParams)

Description

This PR consolidates some imgix props into the imgixParams object, which makes the props API smaller and easier to understand. There should be no issues with excessive re-rendering as the object is checked shallowly to see if the object's values have changed. I decided to deprecate the old props rather than remove them to ease the transition to the new API. Any use of the old props will now trigger a warning, and we will remove the old props in v9.

In the past this library has set the faces imgix parameter by default. The new behaviour is to not set this parameter so that it should be less confusing for new-comers.

Also, I'm looking for good taglines/features about this library, so if you, reader, have any ideas, please let me know.

Ref #144

TODO

  • rename imgProps to htmlAttributes after deciding that imgProps and imgixParam are too similar
  • address PR comments

New Feature

  • If this is a big feature with breaking changes, consider [opening an issue][issues] to discuss first. This is completely up to you, but please keep in mind that your PR might not be accepted.
  • Run unit tests to ensure all existing tests are still passing
  • Add new passing unit tests to cover the code introduced by your PR
  • Update the readme
  • Add some steps so we can test your cool new feature!
  • The PR title is in the conventional commit format: e.g. feat(<area>): added new way to do this cool thing #issue-number
  • Add your info to the contributors array in package.json!

Steps to Test

Review changes to unit tests.

@frederickfogerty frederickfogerty changed the base branch from master to version-8 July 30, 2018 21:41
export default class ReactImgix extends Component {
const defaultImgixParams = {
auto: ["format"],
fit: "crop"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're removing the fit=faces default, we need to also remove the fit=crop default. If it's left on, all images will crop to center instead of resizing as expected.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be noted as a breaking change as well, since people will need to re-add it in their imgixParams (née customParams) if they're intentionally using other crop modes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, fit=crop works intuitively for developers, but it needs to be called out in the README somewhere.

disableSrcSet: PropTypes.bool,
onMounted: PropTypes.func,
sizes: PropTypes.string,
src: PropTypes.string.isRequired,
type: PropTypes.oneOf(validTypes),
width: PropTypes.number,
height: PropTypes.number,
disableLibraryParam: PropTypes.bool
defaultHeight: PropTypes.number,
defaultWidth: PropTypes.number,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think defaultWidth and defaultHeight aren't supposed to be here. Weren't they removed in #159?

Copy link
Contributor Author

@frederickfogerty frederickfogerty Jul 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, they were removed. Those pesky merge commits!

if (params.crop) crop = params.crop;

let fit = false;
if (entropy || faces) fit = "crop";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just go all-in on auto-setting here: if the user provides any kind of crop value, we should automatically set fit=crop (otherwise crop= is always ignored by the painter).

if (!!crop) fit = "crop";

Usually I would object to this kind of "magic" but I can't think of a downside in this case.

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 sounds like a great idea.

...this.props.imgixParams
};

const { faces, entropy } = params;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel a little bit uneasy about encouraging users to put "non-standard" parameters into the imgixParams object. I have no problem putting "helper" options into the parent this.props object, but if we're going to explicitly call this a map of "imgix params" then I feel like we should require users to pass in crop: 'faces' instead of faces: true.

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 had actually forgotten that faces wasn't a top level imgix parameter. I agree with you, I feel uneasy about it as well. I'll remove faces in favour of using crop: 'faces' directly.

children,
component,
customParams,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imgixParams should be added to this.props here, no?

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 don't think so -- this is not setting the prop types for the component, this is destructuring props into local variables to make it easier to use in the render method. imgixParams is not used anywhere in render, only in ReactImgix.buildSrcs()

DEPRECATED_PROPS.forEach(deprecatedProp => {
warning(
!(deprecatedProp in props),
`The prop '${deprecatedProp}' has been deprecated and will be removed in v9. Please update the usage to <Imgix imgixParams={{${deprecatedProp}: value}} />`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following my above comment about not encouraging users to pass in { imgixProps: { entropy: true } }, this warning will need to be updated.

@frederickfogerty
Copy link
Contributor Author

Hey @jayeb, I think I've addressed all the issues discussed - could you please give this another review?

@frederickfogerty frederickfogerty merged commit 9fb0cb9 into version-8 Aug 13, 2018
frederickfogerty added a commit that referenced this pull request Aug 15, 2018
…#163)

BREAKING CHANGES: - picture and source types have been changed to components. 

## Description

**NB: This is currently a stacked PR. I will change the base to `version-8` when #162 is resolved. The last commit in the PR moved some stuff around, it may help to view [this diff](https://github.com/imgix/react-imgix/pull/163/files/0b88acb3f646691ef1df80b207b5e09935df54f5) first to see the feature changes.**

This PR builds on the changes described in #144. Having the picture and source behaviour work using a `type` prop was causing `<Imgix />` to have mixed responsibilities. This was causing pecularities, such as needing to pass a `src` to a `<Imgix type='picture' />` even though it wasn't used. 

### TODO 

- [x] Update Upgrade Guide
- [x] Change imgProps to be htmlAttributes as discussed offline with @jayeb 
~- [ ] Add prop fall-through behaviour to `<Picture />`~

### New Feature

- [x] If this is a big feature with breaking changes, consider [opening an issue][issues] to discuss first. This is completely up to you, but please keep in mind that your PR might not be accepted.
- [x] Run unit tests to ensure all existing tests are still passing
- [x] Add new passing unit tests to cover the code introduced by your PR
- [x] Update the readme
- [x] Add some [steps](#steps-to-test) so we can test your cool new feature!
- [x] The PR title is in the [conventional commit](#conventional-commit-spec) format: e.g. `feat(<area>): added new way to do this cool thing #issue-number`
- [x] Add your info to the [contributors](#packagejson-contributors) array in package.json!

## Steps to Test

Review the changes to the tests.
@frederickfogerty frederickfogerty deleted the fred/reduce-props branch August 15, 2018 21:11
frederickfogerty added a commit that referenced this pull request Aug 15, 2018
* version-8:
  docs: add link to fluid example and fix some links
  docs: add example about fitting to the size of the container
  docs: add ref information
  feat: refactor picture and source behaviour into different components (#163)
  feat: reduce props API surface area (#162)
  feat: implement responsiveness with srcSet and sizes (#159)
  fix: warn the user when no <img> passed as a child to <picture> fixes #90 (#151)

# Conflicts:
#	README.md
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

2 participants