Skip to content

Commit

Permalink
feat: wrap ReactImgix with props HOFs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
luqven committed Jun 17, 2021
1 parent fe87f79 commit 07c1d0a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/HOCs/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./shouldComponentUpdateHOC";
export * from "./imgixProvider"
10 changes: 6 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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;
11 changes: 8 additions & 3 deletions src/react-imgix.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 07c1d0a

Please sign in to comment.