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
Categories
- ActionScript (1)
- AIR (5)
- Cayri (7)
- Design Patterns (4)
- Flex (8)
- Mapping (1)
- Mesh (1)
- Mixbook (1)
Recent Posts
- Mesh – A Persistence Framework For Flex
- Making ActionScript Look Beautiful: Increasing Readability and Loosing Verboseness
- Help Dan find a Flex Engineer and get a free paid trip for 2 to Hawaii
- What’s Happening With Cayri?
- Saving Flex’s Application State to a Database
- Loading Modules/Runtime CSS into an AIR App
- CollectionEventKind.RESET, WTF Does That Mean?
- When to Use Weak References
- Embedding Cayri on Your Website
- The State Pattern in Flex 2
- @zeeyang just get an iPhone already :)
- @neiltyson I'd love to see you speak this week, but damn.. $270!! Your talk costs 3x more than a rock concert.
- @almeida_miguel sorry, but Mixbook doesn't offer licensing of its software at the moment.
- @usbank -1 for telemarketing your own customers.
- I might go to The Black Keys @ San Jose City College. http://t.co/d81dAPfu




