Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

JSConf.eu - React: Rethinking Best Practices

DZone's Guide to

JSConf.eu - React: Rethinking Best Practices

Free Resource

Today I saw a tweet pointing to a JSConf talk by Pete Hunt from Facebook, talking about ReactJS, Facebook's JavaScript frontend framework. Here are my notes.

I like the idea as it focuses on concepts which I consider extremely important: modularity and simplicity as both build the foundation of a more clean and maintainable application architecture.

When you create rich JavaScript apps, you should pay particular attention to its maintainability, which is where automated unit tests come into place which in turn requires you to create potentially small, atomic and loosely coupled components or widgets. That's why many JS frameworks try to address it (take AuraJS,MarionetteJS,..).

Personally I currently use JavaScriptMVC or CanJS which both have the idea of creating widget/components build-in and promoted by their creators.

Having said that, ReactJS looks interesting and I guess I'll give it a try, maybe code the TodoMVC example to get a feeling for it.

My talk notes

  • it's about building components
  • render UI -> respond to events
  • more like the V in MVC
  • doesn't care about how data is fetched, processed etc..focuses on the real presentation logic

Building components

  • reusable components, "reduce coupling, increase cohesion"
  • "Templates encourage a poor separation of concerns" (i.e. Angular)
  • Problem: (view)model binds controller to template; if you need to change the view, you also need to update your controller (most probably)
  • "Templates separate technologies, not concerns"
  • "view partials" are evil (dependency and maintainability hell)
  • "keep components small" -> easier to unit test, less complexity, less spaghetti code

Fast

  • Re-render entire app on every change
  • easy 'cause you simply refresh (like server-side rendering approaches)
  • based on virtual DOM and event system
    • create new virtual DOM
    • diff it with old one
    • batch update diffs
  • can execute on Node
  • same code, client & server; React can directly take and boot upon markup returned from the server.

Key takeaways

  • build components, not templates
  • re-render, not mutate
  • Virtual DOM

Links

Topics:

Published at DZone with permission of Juri Strumpflohner. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}