-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
React < 16.3 support (WIP) #1113
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React, { Component } from 'react'; | ||
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. I'd move it to 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. Ok! |
||
import PropTypes from 'prop-types'; | ||
|
||
export const Context = React.createContext(); | ||
|
||
export function Consumer(WrappedComponent) { | ||
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. I'd call it 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. Ok! |
||
const componentName = WrappedComponent.name.replace(/Renderer$/, ''); | ||
return class extends Component { | ||
static displayName = `Consumer(${componentName})`; | ||
state = {}; | ||
render() { | ||
return ( | ||
<Context.Consumer> | ||
{context => { | ||
if (!context) { | ||
throw new Error(`Consumer cannot be rendered outside the Provider component`); | ||
} | ||
return <WrappedComponent {...context} {...this.props} />; | ||
}} | ||
</Context.Consumer> | ||
); | ||
} | ||
}; | ||
} | ||
|
||
export function Provider(props) { | ||
const { children, ...rest } = props; | ||
const ui = typeof children === 'function' ? children(this.state) : children; | ||
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. Do we really need both here? 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. It will be removed! |
||
|
||
return <Context.Provider value={{ ...rest }}>{ui}</Context.Provider>; | ||
} | ||
|
||
Provider.propTypes = { | ||
children: PropTypes.any, | ||
codeRevision: PropTypes.number.isRequired, | ||
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. You're not using some of these 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. I have copied from this childContextTypes because they are used in several components |
||
config: PropTypes.object.isRequired, | ||
slots: PropTypes.object.isRequired, | ||
displayMode: PropTypes.string, | ||
}; |
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.
Is this change necessary?
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.
Yes, I had problems in Windows, it relates with this issue:
prettier/prettier#4086 (comment)
And here explains that
https://prettier.io/docs/en/cli.html
Maybe it should be other PR
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.
🤦♂️
We should change it here, otherwise the script will overwrite the command eventually:
https://github.com/sapegin/mrm-tasks/blob/master/packages/mrm-task-prettier/index.js#L82
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.
Amazing project @sapegin!