Browsing articles in "Mesh"
Feb 18, 2011

Mesh – A Persistence Framework For Flex

For awhile now, I’ve been wanting to create a framework at Mixbook for managing how data is sent back and forth from our Flex application to the server. We’ve had some downtime recently and I think we’ve come up with something pretty cool for the Flex community. It’s called Mesh, and it’s really simplified our persistence codebase.

In Mesh, you define the mapping of your models to backend services and the associations between your model classes. Mesh uses these definitions to determine how to query your backend for data. For instance, say we have a Customer who has many Order‘s. If you were to call customer.orders.load(), it will execute a find request on the orders service and populate the list with orders belonging to that customer.

Saving is also a lot cleaner. Each model and association has a method called save(). When called, it persists the model object to its defined backend service. Associations also track how your application modifies them. For instance, we can save two new Order‘s to Customer, then later in our code, remove one of the orders and update the order total for the other. When customer.orders.save() is called, Mesh will send a destroy request to the order service for the order that was removed, and an update request for the order thats total has changed.

var order1:Order = new Order();
order1.total = 9.99;
 
var order2:Order = new Order();
order2.total = 19.99;
 
customer.orders = [order1, order2];
customer.orders.save(); // persist order1 and order2 to the orders service
 
// update the total for order1, then remove order2 completely.
order1.total = 1.99;
customer.orders.remove(order2);
customer.orders.save(); // send a remove and update request to the backend service

We’ve also added some other great features, such as data validation and tracking which objects have changed, so only the objects that have been modified and are valid get sent to the server. Mesh is completely agnostic to the backend service you’re using. It can integrate with any REST, SOAP, or AMF service, and hypothetically, it should also be able to work with a SQLite database running in AIR.

Mesh is hosted at GitHub, and I’m progressively adding tutorials and guides on how to use the framework. Note that Mesh is currently in alpha, so there may be parts of the API that change in the coming weeks.

We’re releasing this framework as open source under the MIT license, which means that it’s completely free to use in commercial projects. We welcome feedback on ways to improve the API, or new features that you think would be beneficial to a framework such as this.

About Dan

  • I'm the Lead Software Architect at Mixbook. A rapidly growing online photobooking and scrapbooking company.
  • I built Cayri, an online monitor for flight simulator networks.
  • I enjoy learning guitar, astronomy, beer, music, programming, and driving with no apparent destination.
  • I live in San Jose, CA.

Categories

Twitter