daily pastebin goal
10%
SHARE
TWEET

Untitled

a guest Mar 24th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top