Skip to content
This repository has been archived by the owner on Jul 8, 2023. It is now read-only.

Commit

Permalink
💥 🔧 with-log: refactor using "eager factory"
Browse files Browse the repository at this point in the history
  • Loading branch information
deepsweet committed Aug 19, 2017
1 parent f573633 commit e4acab9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/with-log/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
},
"peerDependencies": {
"react": "^15.6.1",
"recompose": "^0.24.0"
"recompose": "^0.25.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
/* eslint-disable no-console */
import React from 'react';
import { setDisplayName, wrapDisplayName } from 'recompose';
import { createEagerFactory, setDisplayName, wrapDisplayName } from 'recompose';

const withLog = (getMessageToLog = (props) => props) => (Target) => {
if (process.env.NODE_ENV === 'production') {
return Target;
}

const factory = createEagerFactory(Target);
const displayName = wrapDisplayName(Target, 'withLog');

const WithLog = (props) => {
console.log(`${displayName}:`, getMessageToLog(props));

return (
<Target {...props}/>
);
return factory(props);
};

return setDisplayName(displayName)(WithLog);
Expand Down

0 comments on commit e4acab9

Please sign in to comment.