Skip to content

Conversation

@ptitFicus
Copy link
Collaborator

@ptitFicus ptitFicus commented Nov 4, 2017

fixes #49

Hi,

I adapted code of #66 (initially made for #49) to the new version of this HOC.

I also:

  • Changed isInState name to hasStatus: it may still be unclear but a last it's not confusing with react state anymore
  • Factorized the whole coloration code in a util folder. It avoids duplication but util folder is not necessarily a very good pattern: any idea welcome 😊

The is some linting issues, since I call setState in componentDidMount directly 😱, however the old componentDidMount dit already call setState, it was just hidden in the setColor function. 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! 😃

@ptitFicus ptitFicus requested a review from fabienjuif November 4, 2017 16:41
@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 98.795% when pulling 2c4da69 on fallback into b3f2b3a on master.

@fabienjuif
Copy link
Member

Take care, you don't use you SSH key to push those commits.
So your name is the not the right one on commits ;)

return (
<div
title={message}
ref={(c) => { this.div = c }}
Copy link
Member

@fabienjuif fabienjuif Nov 7, 2017

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

Copy link
Collaborator Author

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

>
<path
stroke={color}
strokeWidth="3.03754568"
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clever one :p

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

this.setState({
color: color.toHexString(),
})
const newColor = findCorrectColor(this.svg)
Copy link
Member

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) => {
Copy link
Member

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)) {
Copy link
Member

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]))
Copy link
Member

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

Copy link
Collaborator Author

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', () => {
Copy link
Member

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 ?

Copy link
Collaborator Author

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 =)

return window.getComputedStyle(node, null).getPropertyValue('background-color')
}

export const initialColor = '#cecece'
Copy link
Member

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 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea =)

@fabienjuif fabienjuif changed the title ✨ First draft of fallback component ✨ fallback component Nov 7, 2017
@fabienjuif
Copy link
Member

I renamed your PR so the squash/merge would have a better message to me

Copy link
Member

@fabienjuif fabienjuif left a 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 ;)

@fabienjuif
Copy link
Member

And I update your first post to add the fixes triggered word

@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 98.765% when pulling 9c60ae5 on fallback into b3f2b3a on master.

@fabienjuif
Copy link
Member

fabienjuif commented Nov 8, 2017

Nice job @ptitFicus 👍
Do you want to rebase your branch so you can set the author right ?

  • git rebase -i master
  • set e (edit) instead of pick for each commit
  • For each commit:
    • git commit --amend --author 'Benjamin CAVY <benjamin.cavy@gmail.com>'
    • git rebase --continue
  • then... push -f

@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 98.765% when pulling b7840f9 on fallback into b3f2b3a on master.

@ptitFicus
Copy link
Collaborator Author

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.
Copy link
Member

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.
Copy link
Member

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.

Copy link

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`).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the ``print`` prop ?

Copy link
Collaborator Author

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.

Copy link
Member

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&nbsp;default loader(Base)"
code="export&nbsp;default loader()(Base)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@fabienjuif fabienjuif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README.md review

Copy link
Member

@fabienjuif fabienjuif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

@fabienjuif fabienjuif merged commit 6c86b56 into master Nov 13, 2017
@fabienjuif fabienjuif deleted the fallback branch November 13, 2017 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow to display of a "fallback" component

6 participants