-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Featured Image: Refactor Featured Image to use withApiData
HoC
#2527
Featured Image: Refactor Featured Image to use withApiData
HoC
#2527
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2527 +/- ##
==========================================
+ Coverage 28.49% 30.04% +1.54%
==========================================
Files 169 174 +5
Lines 5148 5505 +357
Branches 859 981 +122
==========================================
+ Hits 1467 1654 +187
- Misses 3119 3234 +115
- Partials 562 617 +55
Continue to review full report at Codecov.
|
The |
onSelect={ onUpdateImage } | ||
type="image" | ||
> | ||
{ media && !! media.data && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
media
should always be an object assigned by withAPIData
, so shouldn't need to test truthiness (except for testing convenience).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but sometimes I don't assign the media
prop at all in the HoC. (When there's no image set)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. In this particular case since we're already in the condition of !! featuredImageId
that would never apply, but probably good to be safe.
@@ -135,4 +79,19 @@ export default connect( | |||
}, | |||
}; | |||
} | |||
); | |||
|
|||
const fetchAPIData = withAPIData( ( { featuredImageId } ) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to use the naming convention discussed at #2525 (comment) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I was waiting for your changes there :). Updating
In this PR, I'm trying to use
withAPIData
in the featured image component and this is a huge improvement over repeating the same lifecycle calls over and over again :)I've noticed a bug and I suspect that the HoC doesn't trigger the requests properly when the URL changes. I may be wrong though. (Try changing the featured image, the new one is not fetched) Any idea @aduth