tl;dr I tried React, and liked it. If we were to decide to go an use it for
our front-end code, I'd be happy.
--
I've been spending a little bit of time over chistmas and this week
learning more about React and applying what I did learn to a concrete
project: re-writing the markup-view panel (only as an experiment).
This email is not about me championing for the idea of using React in the
devtools because I simply don't know enough about it yet (and I'm still
somewhat uncomfortable with introducing a ui lib in a project like this,
knowing that new ui libs come and go very quickly these days).
However, I'm pretty confident after having tried it out that it's a good
fit technically.
Here are some of the advantages I can see:
- It would force us to (re-)write our panels in a consistent manner, making
it easier for new contributors to join (especially if they already know
React, or are interested in trying it out).
- The ui update flow is pretty amazing, just update the model and refresh
everything. The dom diffing mechanism really does seem to be pretty
efficient. I've worked in the past with a similar framework so I know the
feeling of "set something in the model, have the UI automatically update",
but the diff makes the update pretty mind-blowing.
- It enforces a clearer separation between the model and the view layers.
Components are far easier to deal with if they are small, single purposed
and stateless (they only accept input props but don't need to manage a
state of their own), and so with React, you tend to want to write them this
way automatically and that forces better reusability of common widgets.
- After spending a few hours writing a DOM node component to display it as
part of the markup-view, I didn't have anything else to do to make it
usable standalone somewhere else. I can now just render it on its own too
(today, we have specific code to display dom nodes in the variable view and
console).
- That also causes components to be easily swappable too, because they
don't depend on anything else than what input props they take. So, in the
markup-view for instance, I've realized it's very simple to switch from an
HTML-like tree view to a HAML-like tree view.
That's not to say that any of this can't be done without React of course,
most of these are just good design principles and we can apply them without
using React (except of course for the way it updates the DOM), but React
makes this very obvious and easy to do.
If you want to take a look at the code I threw together quickly for the
markup-view, check this bug:
https://bugzilla.mozilla.org/show_bug.cgi?id=1118692
If you decide to apply the patch, be aware that I only have re-implemented
about 20% of the features, so don't expect everything to work as before.
--
Patrick Brosset