-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Angular to React Migration #10271
Comments
Few comments:
The example uses redux... I'm not aware of any decision to use redux.
this does not bring consistency to the code base.... lets decide on one way and follow it across the board.
I don't understand (sorry)... so functions are considered state? |
The plugin example doesn't use redux, it uses flux. As far as I am aware
of there was no decision on any specific state mechanism to use, so I just
picked something to start with.
If you have some other recommendation for managing state that you would
like me to use, please let me know.
On Feb 12, 2017 4:49 PM, "uboness" <notifications@github.com> wrote:
Few comments:
I have a plugin here that will serve as an example
The example uses redux... I'm not aware of any decision to use redux.
Prefer Stateless functional components where possible. When it isn't
possible, use ES6 style React Classes.
this does not bring consistency to the code base.... lets decide on one way
and follow it across the board.
Pass functions via props to avoid storing state in a component.
I don't understand (sorry)... so functions are considered state?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#10271 (comment)>,
or mute
the thread
<https://github.com/notifications/unsubscribe-auth/APy9k9nXOzjc_Ogxg71fs6WQ-ZcKSRNkks5rb352gaJpZM4L8fPd>
.
|
If we plan to move forward with #8315, I think a good baseline is to follow the Airbnb React guidelines too, which has basically the same recommendation as @stacey-gammon (see https://github.com/airbnb/javascript/tree/master/react#class-vs-reactcreateclass-vs-stateless). In my experience this doesn't cause any consistency problems in the codebase, and is very clean and readable (we follow this in Cloud UI too). |
cool... I would still love to understand the rational behind this. I get it that functions are safer... but when state is involved we move to classes.... this makes little sense to me. I still don't understand why we can't have one way of doing something instead of having two. |
I guess it was wrong of me to assume we're using redux based on the redux dependency in We've agreed to move to React and I believe the examples that we offer should solely focus on how to write react components. |
It's just cleaner for the normal case (aka when you don't have state in the component). It also signals clearly that the component doesn't rely on state or other lifecycle events. We use them a whole lot in the "leaf components", as those are usually pure "render your html with the props I'm giving you" style components. |
so basically, we rather no be consistent and have one way of doing something just so instead of: class Label extends React.Component {
render() {
return <div>{this.props.text}</div>;
}
} we do: function Label(text) {
return <div>{text}</div>;
} ? (as a side note... the former clearly indicates to me that it's a react component, the later doesn't) |
Yep. I don't see any problems in that. It's super-easy to add an eslint rule for it too, then we're consistent across the code base. Then we're also consistent with the "recommended approach" (whereby "recommended" == the styleguide we've said we want to rely on) |
The plugin examples repo is far from in a finished state, hence the
"TODO.... Before this can serve as a guide:
- Pick an end spot and finish the plugin, cleaning up all the code
- Team wide code review of concepts and style"
Redux dependency must be left over from Thor which is where I started
from. I will remove it when I clean the rest of it up.
We've agreed to move to React and I believe the examples that we offer
should solely focus on how to write react components
When Court talked to me about the react project, the end goals were very
open ended. What I understood the loose guidelines to be was to create an
example that was more complex than most example components you could find
online, and for it to be kibana specific. I asked about state and that was
left open as well. I started from a few different angles to hopefully
encompass everything: simple react components that would go in the UI
framework (which I am working on and have a couple PRS out), mid level
features that would showcase more of the angular to react interactions (not
yet started), and a top level component to serve as an example if someone
were starting an app from scratch (in progress)
If you think the latter two should not be tackled now then I can certainly
just focus on stateless react components that would go in the UI
framework. Apologies if my understanding of the project was wrong. I'll
touch base with Court tomorrow to be sure we are all on the same page.
On Feb 12, 2017 6:24 PM, "uboness" <notifications@github.com> wrote:
The plugin example doesn't use redux, it uses flux. As far as I am aware
of there was no decision on any specific state mechanism to use, so I just
picked something to start with.
I guess it was wrong of me to assume we're using redux based on the redux
dependency in package.json (why do we have this dependency?)
We've agreed to move to React and I believe the examples that we offer
should solely focus on how to write react components.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#10271 (comment)>,
or mute
the thread
<https://github.com/notifications/unsubscribe-auth/APy9k-cpRKQL1St-gcdqn_ZSKegYiSQWks5rb5S3gaJpZM4L8fPd>
.
|
@stacey-gammon thx all the background... I think it's important that we indeed scope this appropriately. |
interesting.... |
FYI, the Redux dependency is there because the UI Framework documentation site is built using Redux. |
In addition to what's been said, stateless components have two important benefits:
|
you have tight coupling to React anyway regardless of how you look at it. I believe that this argument of trying to minimize the dependency on react comes from the concern of "what happens if one day we want to move away from React... using the function notation will reduce that work". This is a false assumption, as migration will probably require to redefine all components class & functions alike + their unit tests (the fact that React accepts a the function notation is a feature of React). For the rest, I assume the test infra will be there to help easily write simple tests for React components, in which case we should not foresee an overhead in writing these for the simplest components as well.
IMO, first/only valid reason so far... that said, not sure whether or not to categorize it as pre-mature optimization. Do we know, by experience/facts, that this has a significant/meaningful impact? |
It doesn't, it's currently the same performance. Long-term the React team plans to move away from classes (https://twitter.com/dan_abramov/status/817391956041101316, https://twitter.com/dan_abramov/status/745757519994294281). Still early stages, though, so classes will be there for a while. In my experience it improves readability quite a bit (for a couple of reasons: no |
@kjbekkelund actually having React move away from classes is a perfectly valid reason IMO... I was not aware that was the case (and I'm quite surprised as in the past they were promoting classes). Thx for the reference.
can't say if I this is valid for me or not... simply because I don't understand what it means and how it looks like vs. the alternative. |
This process of migrating from Angular to React will be supported by our process of rebuilding our UI with the EUI Framework (#15282). |
EUIfication will carry the torch for this process, closing. |
Angular to React Migration
What this is not
What this is
A slow migration to react, focusing on:
How to get started
When writing a new plugin from scratch
TODO
I have a plugin here that will serve as an example for how to write large react components in our code base when starting from scratch at the app level. Before this can serve as a guide:
When writing a new large feature inside an already existing angular app
TODO
I will be working on rewriting some large parts of dashboard in react that can serve as an example for this specific situation. This will also go through a team wide code review prior to it being accepted as an example we should follow.
Migrating leaf components
Goals
Examples
Gotchas
props.children
:tooltip
prop cause both the react component to display a tooltip, and the angular side of the component as well.Style Guidance
Stateless functional components
where possible. When it isn't possible, use ES6 style React Classes.Kibana Resources
Ground up plugin example:
External Resources
The text was updated successfully, but these errors were encountered: