Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. import { tap, noop, omit } from 'lodash/fp';
  2. import webpIsSupported from 'lib/webpIsSupported';
  3.  
  4. // props we use in the component but don't want to pass down
  5. const BLACKLISTED_PROPS = [
  6. 'onWebpSupportDetermined',
  7. ];
  8.  
  9. const withWebpAwareness = (WrappedComponent) => class extends Component {
  10. state = {
  11. webpSupport: 'unknown',
  12. }
  13. componentDidMount() {
  14. webpIsSupported()
  15. .then(tap(this.setWebpSupport))
  16. .then(tap(this.props.onWebpSupportDetermined || noop));
  17. }
  18. setWebpSupport = (isSupported) => {
  19. this.setState({
  20. webpSupport: isSupported ? 'supported' : 'unsupported',
  21. });
  22. }
  23. render() {
  24. const attributes = omit(BLACKLISTED_PROPS, this.props);
  25. return <WrappedComponent {...attributes} {...this.state} />;
  26. }
  27. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement