Skip to content

Conversation

@youknowriad
Copy link
Contributor

props @aduth

addresses #894 (comment)

@youknowriad youknowriad added the General Interface Parts of the UI which don't fall neatly under other labels. label May 26, 2017
@youknowriad youknowriad self-assigned this May 26, 2017
@youknowriad youknowriad requested a review from aduth May 26, 2017 14:11
Copy link
Member

Choose a reason for hiding this comment

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

Should be tabs here.

Copy link
Member

Choose a reason for hiding this comment

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

Cool 👍 So to be clear, neither the done nor fail case are invoked when the request is aborted?

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 think so, I tested once but Let me test against to be absolutely certain :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch @aduth the abort was being triggered :( So, now I'm ignoring aborted request in the fail callback.

@youknowriad youknowriad force-pushed the add/responsive-image branch from c1c18e0 to dda7322 Compare May 26, 2017 15:45
Copy link
Member

Choose a reason for hiding this comment

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

I dislike acronyms, especially e, because it takes me a moment to distinguish intent between the event and error common use-cases. I'm always happier with the verbose equivalent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's make Andrew Happy 🙂. You're absolutely right, this is a bad habit of mine

@youknowriad youknowriad force-pushed the add/responsive-image branch from b26b340 to 2a872d7 Compare May 26, 2017 16:07
.fail( () => {
if ( this.props.featuredImageId !== mediaIdToLoad ) {
.fail( ( error ) => {
if ( error && error.statusText === 'abort' ) {
Copy link
Member

Choose a reason for hiding this comment

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

Looking to the docs, the first argument is not the error, but the jqXHR instance:

http://api.jquery.com/jQuery.ajax/#jqXHR

Is it ever falsey?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch

return (
<div className="components-responsive-image">
<div style={ imageStyle } />
<img src={ src } className="components-responsive-image__image" alt={ alt } />
Copy link
Member

Choose a reason for hiding this comment

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

In the future, or perhaps even now, we may want to make this component a bit more generic as a responsive panel. The padding technique is rarely used with images, except in this case where we don't know the rendered width, and often more for background images or video elements. It could also help avoid the need to overwhelm the props with individual img attributes we want to assign, if we instead accepted the img as a child.

Not too concerned about this being addressed here.

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 tried to handle this, I've renamed ResponsiveImage as ResponsiveWrapper and it works by checking that the children is a single React Element and then cloning the element to add the class name. Does this sound good for you?

@youknowriad youknowriad force-pushed the add/responsive-image branch from 2765064 to 2d054a6 Compare May 31, 2017 11:38
@youknowriad
Copy link
Contributor Author

Rebased here. @aduth do you have time to look at this again?

import './style.scss';

function ResponsiveWrapper( { naturalWidth, naturalHeight, children } ) {
if ( ! children || Array.isArray( children ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

I think we don't want to test children as an array, but rather Children.count > 1

https://facebook.github.io/react/docs/react-api.html#react.children.count

Or even Children.only if we don't mind being very noisy (thrown errors) with incorrect usage:

https://facebook.github.io/react/docs/react-api.html#react.children.only

Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

Looks great 👍

@youknowriad youknowriad merged commit 5b0a31a into master Jun 1, 2017
@youknowriad youknowriad deleted the add/responsive-image branch June 1, 2017 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

General Interface Parts of the UI which don't fall neatly under other labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants