Skip to content

Commit

Permalink
Format packages/compose with Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnajdr committed Oct 21, 2019
1 parent f5b5201 commit 2952401
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 77 deletions.
19 changes: 10 additions & 9 deletions packages/compose/src/higher-order/if-condition/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ import createHigherOrderComponent from '../../utils/create-higher-order-componen
*
* @return {Function} Higher-order component.
*/
const ifCondition = ( predicate ) => createHigherOrderComponent(
( WrappedComponent ) => ( props ) => {
if ( ! predicate( props ) ) {
return null;
}
const ifCondition = ( predicate ) =>
createHigherOrderComponent(
( WrappedComponent ) => ( props ) => {
if ( ! predicate( props ) ) {
return null;
}

return <WrappedComponent { ...props } />;
},
'ifCondition'
);
return <WrappedComponent { ...props } />;
},
'ifCondition'
);

export default ifCondition;
4 changes: 3 additions & 1 deletion packages/compose/src/higher-order/pure/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ const pure = createHigherOrderComponent( ( Wrapped ) => {
if ( Wrapped.prototype instanceof Component ) {
return class extends Wrapped {
shouldComponentUpdate( nextProps, nextState ) {
return ! isShallowEqual( nextProps, this.props ) || ! isShallowEqual( nextState, this.state );
return (
! isShallowEqual( nextProps, this.props ) || ! isShallowEqual( nextState, this.state )
);
}
};
}
Expand Down
18 changes: 10 additions & 8 deletions packages/compose/src/higher-order/pure/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ describe( 'pure', () => {

it( 'class component should rerender if the props or state change', () => {
let i = 0;
const MyComp = pure( class extends Component {
constructor() {
super( ...arguments );
this.state = {};
const MyComp = pure(
class extends Component {
constructor() {
super( ...arguments );
this.state = {};
}
render() {
return <p>{ ++i }</p>;
}
}
render() {
return <p>{ ++i }</p>;
}
} );
);
const wrapper = mount( <MyComp /> );
wrapper.update(); // Updating with same props doesn't rerender
expect( wrapper.html() ).toBe( '<p>1</p>' );
Expand Down
4 changes: 1 addition & 3 deletions packages/compose/src/higher-order/with-instance-id/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ export default createHigherOrderComponent( ( WrappedComponent ) => {
}

render() {
return (
<WrappedComponent { ...this.props } instanceId={ this.instanceId } />
);
return <WrappedComponent { ...this.props } instanceId={ this.instanceId } />;
}
};
}, 'withInstanceId' );
79 changes: 38 additions & 41 deletions packages/compose/src/higher-order/with-safe-timeout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,43 @@ import createHigherOrderComponent from '../../utils/create-higher-order-componen
*
* @return {Component} Wrapped component.
*/
const withSafeTimeout = createHigherOrderComponent(
( OriginalComponent ) => {
return class WrappedComponent extends Component {
constructor() {
super( ...arguments );
this.timeouts = [];
this.setTimeout = this.setTimeout.bind( this );
this.clearTimeout = this.clearTimeout.bind( this );
}

componentWillUnmount() {
this.timeouts.forEach( clearTimeout );
}

setTimeout( fn, delay ) {
const id = setTimeout( () => {
fn();
this.clearTimeout( id );
}, delay );
this.timeouts.push( id );
return id;
}

clearTimeout( id ) {
clearTimeout( id );
this.timeouts = without( this.timeouts, id );
}

render() {
return (
<OriginalComponent
{ ...this.props }
setTimeout={ this.setTimeout }
clearTimeout={ this.clearTimeout }
/>
);
}
};
},
'withSafeTimeout'
);
const withSafeTimeout = createHigherOrderComponent( ( OriginalComponent ) => {
return class WrappedComponent extends Component {
constructor() {
super( ...arguments );
this.timeouts = [];
this.setTimeout = this.setTimeout.bind( this );
this.clearTimeout = this.clearTimeout.bind( this );
}

componentWillUnmount() {
this.timeouts.forEach( clearTimeout );
}

setTimeout( fn, delay ) {
const id = setTimeout( () => {
fn();
this.clearTimeout( id );
}, delay );
this.timeouts.push( id );
return id;
}

clearTimeout( id ) {
clearTimeout( id );
this.timeouts = without( this.timeouts, id );
}

render() {
return (
<OriginalComponent
{ ...this.props }
setTimeout={ this.setTimeout }
clearTimeout={ this.clearTimeout }
/>
);
}
};
}, 'withSafeTimeout' );

export default withSafeTimeout;
8 changes: 1 addition & 7 deletions packages/compose/src/higher-order/with-state/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,7 @@ export default function withState( initialState = {} ) {
}

render() {
return (
<OriginalComponent
{ ...this.props }
{ ...this.state }
setState={ this.setState }
/>
);
return <OriginalComponent { ...this.props } { ...this.state } setState={ this.setState } />;
}
};
}, 'withState' );
Expand Down
10 changes: 4 additions & 6 deletions packages/compose/src/hooks/use-reduced-motion/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@ import useMediaQuery from '../use-media-query';
*
* @type {boolean}
*/
const IS_IE =
typeof window !== 'undefined' &&
window.navigator.userAgent.indexOf( 'Trident' ) >= 0;
const IS_IE = typeof window !== 'undefined' && window.navigator.userAgent.indexOf( 'Trident' ) >= 0;

/**
* Hook returning whether the user has a preference for reduced motion.
*
* @return {boolean} Reduced motion preference value.
*/
const useReducedMotion =
process.env.FORCE_REDUCED_MOTION || IS_IE ?
() => true :
() => useMediaQuery( '(prefers-reduced-motion: reduce)' );
process.env.FORCE_REDUCED_MOTION || IS_IE
? () => true
: () => useMediaQuery( '(prefers-reduced-motion: reduce)' );

export default useReducedMotion;
1 change: 0 additions & 1 deletion packages/compose/src/index.native.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// Web exports
export * from './index.js';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ function createHigherOrderComponent( mapComponentToEnhancedComponent, modifierNa
return ( OriginalComponent ) => {
const EnhancedComponent = mapComponentToEnhancedComponent( OriginalComponent );
const { displayName = OriginalComponent.name || 'Component' } = OriginalComponent;
EnhancedComponent.displayName = `${ upperFirst( camelCase( modifierName ) ) }(${ displayName })`;
EnhancedComponent.displayName = `${ upperFirst(
camelCase( modifierName )
) }(${ displayName })`;

return EnhancedComponent;
};
Expand Down

0 comments on commit 2952401

Please sign in to comment.