Dev Chats: Spike Brehm of Airbnb
CommonJS + Rails
To solve this problem, Airbnb made a Ruby gem for bridging Sprockets and Gulp. This allowed them to leverage the environment-specific asset serving and deployment from Sprockets while using Gulp and Browersify for bundling and dependency management. It’s currently a private gem, but it should be publicly available before too long.
Backbone -> React
Spike also described Airbnb’s new direction for their front-end infrastructure. Since Airbnb began using Backbone in 2011, new libraries have emerged which he believes are compelling enough to reconsider their stack.
In particular Spike has been interested in Facebook’s React.js library. React seems to be a good solution for replacing existing Backbone view code as it is “very well-scoped” according to Spike. It solves the “V” layer in MVC which is typically the most complex part of front-end web apps.
Spike began by describing some of the challenges he has encountered maintaining Backbone code. Backbone subviews and jQuery plugins often modify the app state after a view gets rendered and thereby prevent a full re-render without losing some of that newly added state and incurring a performance hit. Manually syncing state between templates and views also leads developers to write code that asks questions like “Is this DOM element visible?” or “Is this class applied?” which becomes complex to manage in a nested view structure.
While Backbone requires two-way state syncing between templates and views, React provides a unidirectional data flow and a single way to render HTML to the DOM. Instead of writing state transition code, you describe what the DOM looks like given a certain state, and if the state changes, React handles all the corresponding transitions for you.
Thanks to Spike for taking some time to share what he’s been working on at Airbnb. I look forward to seeing more open source tooling by Airbnb in the future!