From 07c1d0ab6e6215a42498a712e6a1bee3ef1e050c Mon Sep 17 00:00:00 2001 From: Luis Ball Date: Mon, 24 May 2021 14:54:13 -0400 Subject: [PATCH] feat: wrap ReactImgix with props HOFs This commit wraps all the ReactImgix components with the higher order functions that process and merge the Providers props with the Component props. This simplifies the usage of the ImgixContext wrapper for the user. As the HOF will apply the context and merge its props with the user's imgix Component props behind the scenes. In brief, this makes it so the user only needs to worry about adding the ImgixContext component. --- src/HOCs/index.js | 1 + src/index.js | 10 ++++++---- src/react-imgix.jsx | 11 ++++++++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/HOCs/index.js b/src/HOCs/index.js index da6e3f58..2a7fd4ad 100644 --- a/src/HOCs/index.js +++ b/src/HOCs/index.js @@ -1 +1,2 @@ export * from "./shouldComponentUpdateHOC"; +export * from "./imgixProvider" \ No newline at end of file diff --git a/src/index.js b/src/index.js index b637b73a..c83362a8 100644 --- a/src/index.js +++ b/src/index.js @@ -1,10 +1,12 @@ import ReactImgix, { Picture, Source } from "./react-imgix"; import { PublicConfigAPI } from "./config"; - import { buildURLPublic as buildURL } from "./constructUrl"; -export { buildURL }; +import { + ImgixProvider, +} from "./HOCs" -export default ReactImgix; +export { ImgixProvider }; +export { buildURL }; export { Picture, Source, PublicConfigAPI }; - export { Background } from "./react-imgix-bg"; +export default ReactImgix; diff --git a/src/react-imgix.jsx b/src/react-imgix.jsx index 8cf76a05..aea878f3 100644 --- a/src/react-imgix.jsx +++ b/src/react-imgix.jsx @@ -9,6 +9,7 @@ import constructUrl, { } from "./constructUrl"; import extractQueryParams from "./extractQueryParams"; import { ShouldComponentUpdateHOC } from "./HOCs"; +import { mergeComponentPropsHOF, processPropsHOF } from "./HOFs"; const NODE_ENV = process.env.NODE_ENV; @@ -367,9 +368,13 @@ class SourceImpl extends Component { } SourceImpl.displayName = "ReactImgixSource"; -const ReactImgixWrapped = compose(ShouldComponentUpdateHOC)(ReactImgix); -const Picture = compose(ShouldComponentUpdateHOC)(PictureImpl); -const Source = compose(ShouldComponentUpdateHOC)(SourceImpl); +let ReactImgixWrapped = compose()(ShouldComponentUpdateHOC)(ReactImgix); +let Picture = compose()(ShouldComponentUpdateHOC)(PictureImpl); +let Source = compose()(ShouldComponentUpdateHOC)(SourceImpl); + +ReactImgixWrapped = mergeComponentPropsHOF(processPropsHOF(ReactImgix)) +Picture = mergeComponentPropsHOF(processPropsHOF(PictureImpl)) +Source = mergeComponentPropsHOF(processPropsHOF(SourceImpl)) export default ReactImgixWrapped; export {