-
Notifications
You must be signed in to change notification settings - Fork 6
✨ fallback component #85
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
Conversation
|
Take care, you don't use you SSH key to push those commits. |
src/ErrorCross/ErrorCross.jsx
Outdated
| return ( | ||
| <div | ||
| title={message} | ||
| ref={(c) => { this.div = c }} |
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.
Now I prefer to do this :
class extends Component {
attach: (div) => {
const newColor = findCorrectColor(div)
if (this.state.color !== newColor) {
this.setState({ color: newColor })
}
}
render () {
return <div ref={this.attach} />
}
}So I am sure of the order, and I don't rely on the this context
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.
Nice pattern, I'll change it
src/ErrorCross/ErrorCross.jsx
Outdated
| > | ||
| <path | ||
| stroke={color} | ||
| strokeWidth="3.03754568" |
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.
What a precision :)
| } | ||
| } | ||
|
|
||
| const { string, object } = PropTypes |
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.
clever one :p
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.
👏
src/TailSpin/TailSpin.jsx
Outdated
| this.setState({ | ||
| color: color.toHexString(), | ||
| }) | ||
| const newColor = findCorrectColor(this.svg) |
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.
Same comment as before (attach method)
src/core.jsx
Outdated
| if (print === undefined) { | ||
| const { loaded } = props | ||
| return loaded === undefined ? true : !!loaded | ||
| const hasStatus = (prop, propProcessor, defaultProp, defaultValue) => (props, state, context) => { |
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.
hasStatus should be before the export default, so the function is not created for each HOC.
|
|
||
| render() { | ||
| if (!isLoaded(this.props, this.state, this.context)) { | ||
| if (isInError(this.props, this.state, this.context)) { |
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 will avoid negative test and else :
if (isInError) return <ErrorIndicator ...
if (isLoaded) return <ComposedComponent ...
return <LoadingIndicator ...
src/core.jsx
Outdated
| .map(p => Boolean(props[p])) | ||
| .reduce((allProps, currentProp) => allProps && currentProp) | ||
| if (Array.isArray(prop)) { | ||
| const boolProps = prop.map(p => Boolean(props[p])) |
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 avoir this to kind of writing (I know this was the case before, you can open an issue if you want to argue).
But here in hasStatus we have !! technique and Boolean technique
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.
You're right, using both is confusing, I'll switch to !! here
| }) | ||
| }) | ||
|
|
||
| describe('error parameter', () => { |
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.
Nice 👍
What do you think of this new style of writing our test here ?
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.
That's actuelly pretty cool =)
src/utils/colorUtil.js
Outdated
| return window.getComputedStyle(node, null).getPropertyValue('background-color') | ||
| } | ||
|
|
||
| export const initialColor = '#cecece' |
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.
Do we have to use UPPER_CASE convention for constants ?
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.
Good idea =)
|
I renamed your PR so the squash/merge would have a better message to me |
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.
Very good one.
Thank you for the reactivity 😃
I made some comments above, feel free to open issues if you think this is out of this PR scope.
And feel free to argue ;)
|
And I update your first post to add the |
|
Nice job @ptitFicus 👍
|
|
Thanks for the advice @fabienjuif ! I was about to give up on this author mess 😄 I added a dedicated section to the README + I updated project version. |
README.md
Outdated
| The `print` parameter can also be a function. Then the `props` and `context` are given to it (in this order), and it should return a boolean indicating wether or not the actual component should be displayed. | ||
|
|
||
| ### Error handling | ||
| The `error` parameter allow to specify a prop that indicates wether or not a placeholder error component should be displayed in replacement of the real component. |
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.
allows
README.md
Outdated
|
|
||
| ### Error handling | ||
| The `error` parameter allow to specify a prop that indicates wether or not a placeholder error component should be displayed in replacement of the real component. | ||
| It's usefull when data that are mandatory for the correct display of a component are missing. |
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.
I think this is @hgwood, but someone once tells me to use required instead of mandatory.
I can't remember why tho.
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.
It's just way more common to use "required". "mandatory" is more formal. In general shorter words are preferred (eg speed vs velocity, give up vs abandon, build vs construct...). I often use the shortcut that if it's French-sounding, then it's formal :).
| The `error` parameter allow to specify a prop that indicates wether or not a placeholder error component should be displayed in replacement of the real component. | ||
| It's usefull when data that are mandatory for the correct display of a component are missing. | ||
|
|
||
| Like for the `print` prop, `error` can be a `boolean`, a `string` (referencing a prop name), an array of `string` (an array of prop names) or a `function` (whose result will be converted to `boolean`). |
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.
As the ``print`` prop ?
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.
Are you sure about this one ? English is not my strong suit however I think using "as" would mean that error could be use in place of print.
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.
ok
| className={styles.example} | ||
| link="ErrorIndicator" | ||
| code="export default loader(Base)" | ||
| code="export default loader()(Base)" |
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.
👍
fabienjuif
left a comment
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.
README.md review
fabienjuif
left a comment
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.
👌
fixes #49
Hi,
I adapted code of #66 (initially made for #49) to the new version of this HOC.
I also:
isInStatename tohasStatus: it may still be unclear but a last it's not confusing with reactstateanymoreThe is some linting issues, since I call
setStateincomponentDidMountdirectly 😱, however the oldcomponentDidMountdit already callsetState, it was just hidden in thesetColorfunction. We should either change linting rules or find a new color strategy.README is missing an explicative section about this improvement, but I would like to make sure we all agree on this before writting it.
Let's talk about this again! 😃