/faux

Use convention over configuration to host your views and controllers in a "single page browser application"

Primary LanguageJavaScript

Faux

Faux is a Javascript utility for building Single Page Interface (or "SPI") applications.

Single Page Interface applications are much more responsive than traditional server-side client applications. Traditional applications fetch a complete page from the server as part of every interaction. The HTTP model and the architecture of browsers imposes a large overhead on every page displayed. SPI applications load one page and thereafter all changes to the page are handled in the browser using Javascript to manipulate the DOM. Interactions with the server are handled in the background using AJAX. The result is a much faster user experience that features a finer-grained, richer model of interaction.

Faux helps you write SPI applications by providing a traditional page-centric application model, but implementing that model in the browser instead of the server. Faux applications have "pages" that are constructed using Haml templates from models. Faux applications have "routes" that can be bookmarked.

Faux applications are familiar to anyone comfortable writing server applications using frameworks like Rails, and Faux may be the very best way to refactor a traditional server application by separating the business logic in a RESTful server from the application logic in the browser.

Faux may also be the easiest way to transition from writing server applications to SPI applications. Faux applications are built out of Backbone.js's models, views, and controllers. But Faux isn't a framework: Faux doesn't ask you to learn a new, non-portable abstraction in lieu of using MVC.

Instead, Faux provides you with a very simple DSL for defining controller methods, the routes that invoke them, and the templates that should be displayed. From there you gradually add functionality as you need it: You can write View classes for handling interaction, model classes for automatically managing state in the browser, or collection classes for managing filtering and reporting of data sets. You can break pages into components and use all of Faux and backbone.js's tools—like templates, views, and models—to render and control each component. You can add finer- and finer-grained interactivity directly to the View and Model classes you write.

Dive into Faux!

More Reading

why we created faux

We were building an application that mapped neatly onto a traditional CRUD server-side interface, however it was important for us to segregate the domain logic into a domain entity server and the UI into a separate application-specific code base. While in theory this is easy to do in a single Rails application, our experience is that in practice, domain and application logic blur. So we looked at building two Rails applications, a RESTful domain logic server and an application server using ActiveResource as model proxies.

Once we realized how much Javascript we'd be adding to support application logic in the client, the idea of having what amounts to three separate code bases became unpalatable, so we embarked on building all of the application logic into the client and keeping the domain server lean, mean, clean, and RESTful.

Thus, Faux is optimized to act as a font end for a RESTful domain logic server.

other approaches

Faux is not a one-size-fits-all for writing SPI applications.

  • Some applications are extremely simple and don't need the support for events and interaction that views provide. A framework like Sammy might be a good choice.
  • Some applications are small but need some support for interaction. Using Backbone.js directly might be the best choice, as this example shows.
  • Many client-side applications ought to feature rich and varied interaction that doesn't revolve around routes. You might want to roll your own code on top of Backbone.js or jump right into a more sophisticated tool like Sproutcore.

note

Faux was conceived on August 19, 2010 as "Roweis." A remark by Jeremy Ashkenas that we were creating a "Faux Server API" led to its new name.

Faux and its documentation is still a work in progress: Future additions to this documentation may or may not include discussions about handling error codes, directly invoking methods, unobtrusive handlers, and some of the other macros such as title, infers, redirects_to, and location.

Faux was created with the support of the International Development Research Centre, a Canadian Crown Corporation created by the Parliament of Canada that supports research in developing countries to promote growth and development. Faux powers software used by the Think Tank Initiative, a multi-donor program dedicated to strengthening independent policy research institutions—or “think tanks” —in developing countries.