-
Notifications
You must be signed in to change notification settings - Fork 2
Refactor: PR #1 feedback #4
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
Changes from 11 commits
258eac7
02705dc
a2f71df
cb13773
d771456
347693c
ed07a7f
a05b898
3f13430
4e224ee
445369e
480cf24
e676e43
fbf3afd
48bc0f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,9 @@ | ||
# OS X | ||
.DS_Store | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git | ||
node_modules | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# typescript dist | ||
dist/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
tsconfig.json | ||
src | ||
.vscode | ||
.github | ||
.editorconfig | ||
.prettierrc | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
{ | ||
"trailingComma": "all", | ||
"printWidth": 100, | ||
"tabWidth": 2, | ||
"singleQuote": true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,19 +5,26 @@ | |
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"dependencies": { | ||
"react": "^16.4.0" | ||
"react": "^16.4.0", | ||
"@types/react": "^16.3.17" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^16.3.17", | ||
"typescript": "^2.9.1" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"compile": "tsc", | ||
"prepublishOnly": "npm run compile" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/unsplash/react-progressive-enhancement.git" | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "Sami Jaber", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/unsplash/react-progressive-enhancement/issues" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,11 @@ import * as React from 'react'; | |
import { Consumer, ProgressiveEnhancementProp } from './context'; | ||
import { ObjectOmit, getDisplayName } from './helpers'; | ||
|
||
export const withIsEnhanced = function<OwnProps extends ProgressiveEnhancementProp>( | ||
export const withIsEnhanced = <OwnProps extends ProgressiveEnhancementProp>( | ||
ComposedComponent: React.ComponentType<OwnProps>, | ||
) { | ||
type OwnPropsWithoutProgressiveEnhancementProp = ObjectOmit<OwnProps, ProgressiveEnhancementProp>; | ||
|
||
const ComponentWithIsEnhanced: React.SFC<OwnPropsWithoutProgressiveEnhancementProp> = props => ( | ||
) => { | ||
type ComponentWithIsEnhancedType = React.SFC<ObjectOmit<OwnProps, ProgressiveEnhancementProp>>; | ||
const ComponentWithIsEnhanced: ComponentWithIsEnhancedType = props => ( | ||
<Consumer> | ||
{({ isEnhanced }) => <ComposedComponent isEnhanced={isEnhanced} {...props} />} | ||
</Consumer> | ||
|
@@ -19,7 +18,9 @@ export const withIsEnhanced = function<OwnProps extends ProgressiveEnhancementPr | |
return ComponentWithIsEnhanced; | ||
}; | ||
|
||
export const progressivelyEnhance = function<Props>(ComposedComponent: React.ComponentType<Props>) { | ||
export const progressivelyEnhance = <Props extends {}>( | ||
ComposedComponent: React.ComponentType<Props>, | ||
) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To use generics with arrow functions in |
||
const ProgressivelyEnhance: React.SFC<Props> = props => ( | ||
<Consumer> | ||
{({ isEnhanced }) => (isEnhanced ? <ComposedComponent {...props} /> : null)} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { ComponentType } from 'react'; | ||
|
||
export const getDisplayName = (ComposedComponent: ComponentType<any>) => | ||
ComposedComponent.displayName || 'Component'; | ||
ComposedComponent.displayName !== undefined ? ComposedComponent.displayName : 'Component'; | ||
|
||
export type Omit<T, K> = Pick<T, Exclude<keyof T, K>>; | ||
export type ObjectOmit<T extends K, K> = Omit<T, keyof K>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a comment at the top to say that Prettier will inherit from here? E.g. https://github.com/unsplash/web-ops/blob/7352b543ae110247b005cb60226c6adf213401b1/.editorconfig#L1