FOAM Framework

3 min read Original article ↗

Fast apps fast

High-level

You write very high-level, declarative models, and FOAM builds many features from them: default views, storage, serialization, Java and Swift classes, and much more.

Compact

Your app and FOAM itself are both modeled, keeping your payload small.

Our Gmail app is 150KB unzipped.

With so little code to write, FOAM is perfect for rapid app development.

Fast

FOAM apps are small and load fast – even on mobile.

FOAM's reactive programming is efficient, and fast enough for animation – even on mobile.

FOAM is an open-source modeling framework developed at Google.

With FOAM, you create a model, and FOAM can support many features based on it:

  • A (Javascript, Java or Swift) class, with diff(), clone(), and more.
  • Serialization to and from JSON, XML and protocol buffers.
  • Storage in many places, from IndexedDB to MongoDB.
  • Query parsers and a query optimizer.
  • Offline-friendly syncing, and many flavours of caching.
  • Customizable detail and summary views for HTML, Android and iOS.

FOAM combines these features with reactive programming, an MVC library, and a suite of view components for each platform. The result is a full-stack framework for building modern, cross-platform apps.

Try FOAM Live

Below is a FOAM model you can edit, and a list of FOAM features you can see live in your browser.

Try uncommenting the 'hometown' property. Or try changing the defaultValue for the gender property to 'F'.

dao.where(AND(
    GT(Person.AGE, 30),
    CONTAINS(Person.NAME, 'John')))
  .limit(10)
  .orderBy(Person.NAME)
  .select();
dao.put(myPerson);
dao.find(someID);

See the DAO Guide for more on the API.

Here are a few of the supported backends:

  • Lightning fast in-memory cache
  • LocalStorage and IndexedDB in the browser
  • MongoDB
  • Firebase
  • Postgres, SQLite and other SQL databases
  • JSON and XML files
  • clone()
  • copyFrom()
  • hashCode()
  • compareTo() and equals()
  • Observer support: Events for changes to a property, or any property
  • Query parsers (eg. age>=30, name:John)

FOAM includes DAO decorators that add these features to any DAO:

  • Caching (eager or lazy)
  • Offline sync
  • Client-server bridge
  • Journaling
  • Logging
  • Performance measurement

It's all the same API, so it's a one-line change to switch from fake data in memory to offline-ready syncing from a server into IndexedDB.

Links

Sample Apps