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

refactor loading and error #292

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: withFragement should return a function that accepts a compo…
…nent

This update withFragment to interopt with compose and react-recompose
which expect all HoCs to accept a single argument that is the
component.
  • Loading branch information
cbarber committed Aug 4, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit fb31a8ab1c3520a4bac0a12a411ca8a0d36dcd46
2 changes: 1 addition & 1 deletion app/javascript/components/bathroom.jsx
Original file line number Diff line number Diff line change
@@ -52,4 +52,4 @@ Bathroom.defaultProps = {
error: false,
};

export default withFragment(Bathroom, { location: getBathroomCode });
export default withFragment({ location: getBathroomCode })(Bathroom);
2 changes: 1 addition & 1 deletion app/javascript/components/date.jsx
Original file line number Diff line number Diff line change
@@ -83,4 +83,4 @@ export class Date extends React.Component {
}
}

export default withFragment(Date, { location: getTimeZone });
export default withFragment({ location: getTimeZone })(Date);
6 changes: 4 additions & 2 deletions app/javascript/components/hocs/with-fragment.jsx
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import { filter } from 'graphql-anywhere';
* withFragment returns a component which expects props that match
* WrappedComponent's fragment names
*/
export default function withFragment(WrappedComponent, fragmentObject) {
export const withFragment = fragmentObject => WrappedComponent => {
const Enhanced = React.memo(props => {
const fragmentKeys = Object.keys(fragmentObject);
const fragmentDataProps = fragmentKeys.reduce((accProps, fragmentKey) => {
@@ -20,4 +20,6 @@ export default function withFragment(WrappedComponent, fragmentObject) {
});

return Enhanced;
}
};

export default withFragment;
4 changes: 2 additions & 2 deletions app/javascript/components/hocs/with-fragment.test.jsx
Original file line number Diff line number Diff line change
@@ -43,9 +43,9 @@ describe('withFragment higher order component', () => {
});
return 'testComponent rendered';
};
const WrappedComponent = withFragment(testComponent, {
const WrappedComponent = withFragment({
location: locationQuery,
});
})(testComponent);
expect(
ReactTestRenderer.create(
<WrappedComponent location={locationData} />,
2 changes: 1 addition & 1 deletion app/javascript/components/side-panel.jsx
Original file line number Diff line number Diff line change
@@ -86,4 +86,4 @@ SidePanel.defaultProps = {
error: false,
};

export default withFragment(SidePanel, { location: getSidePanel });
export default withFragment({ location: getSidePanel })(SidePanel);
2 changes: 1 addition & 1 deletion app/javascript/components/time-hero.jsx
Original file line number Diff line number Diff line change
@@ -33,4 +33,4 @@ TimeHero.defaultProps = {
error: false,
};

export default withFragment(TimeHero, { location: getTimeHero });
export default withFragment({ location: getTimeHero })(TimeHero);
2 changes: 1 addition & 1 deletion app/javascript/components/top-corner-controller.jsx
Original file line number Diff line number Diff line change
@@ -75,4 +75,4 @@ TopCorner.defaultProps = {
error: false,
};

export default withFragment(TopCorner, { location: getTopCorner });
export default withFragment({ location: getTopCorner })(TopCorner);
2 changes: 1 addition & 1 deletion app/javascript/components/widget-display.jsx
Original file line number Diff line number Diff line change
@@ -166,4 +166,4 @@ export const WidgetDisabledDisplay = () => (
</Wrapper>
);

export default withFragment(WidgetDisplay, { location: getWidgetDisplay });
export default withFragment({ location: getWidgetDisplay })(WidgetDisplay);
Original file line number Diff line number Diff line change
@@ -20,4 +20,4 @@ CurrentTemp.propTypes = {
}).isRequired,
};

export default withFragment(CurrentTemp, { weather: getCurrentTemp });
export default withFragment({ weather: getCurrentTemp })(CurrentTemp);
Original file line number Diff line number Diff line change
@@ -60,4 +60,4 @@ CurrentWeather.defaultProps = {
useLargeIcon: false,
};

export default withFragment(CurrentWeather, { weather: getCurrentWeather });
export default withFragment({ weather: getCurrentWeather })(CurrentWeather);
Original file line number Diff line number Diff line change
@@ -92,4 +92,4 @@ DailyWeather.propTypes = {
}).isRequired,
};

export default withFragment(DailyWeather, { weather: getDailyWeather });
export default withFragment({ weather: getDailyWeather })(DailyWeather);
Original file line number Diff line number Diff line change
@@ -98,4 +98,4 @@ HourlyTemps.defaultProps = {
hours: 5,
};

export default withFragment(HourlyTemps, { weather: getHourlyWeather });
export default withFragment({ weather: getHourlyWeather })(HourlyTemps);
Original file line number Diff line number Diff line change
@@ -140,7 +140,7 @@ SunriseSunset.propTypes = {
weather: PropTypes.shape({}).isRequired,
};

export default withFragment(SunriseSunset, {
export default withFragment({
weather: getSunriseSunsetWeather,
location: getSunriseSunsetLocation,
});
})(SunriseSunset);
Original file line number Diff line number Diff line change
@@ -509,4 +509,4 @@ WeatherEffect.propTypes = {
}).isRequired,
};

export default withFragment(WeatherEffect, { weather: getWeatherEffect });
export default withFragment({ weather: getWeatherEffect })(WeatherEffect);
Original file line number Diff line number Diff line change
@@ -26,4 +26,4 @@ CurrentIcon.propTypes = {
}).isRequired,
};

export default withFragment(CurrentIcon, { weather: getCurrentIcon });
export default withFragment({ weather: getCurrentIcon })(CurrentIcon);
2 changes: 1 addition & 1 deletion app/javascript/components/wifi.jsx
Original file line number Diff line number Diff line change
@@ -79,4 +79,4 @@ Wifi.defaultProps = {
error: false,
};

export default withFragment(Wifi, { location: getWifi });
export default withFragment({ location: getWifi })(Wifi);