Writing better frameworks

At my day job, I am writing a cross platform application framework, specifically targeting devices in the tablet space. As a result, I have been in a very nice position to evaluate different approaches to developing web application frameworks on multiple devices that all share a common browser base, namely webkit.

While Phos is aiming at being entirely procedural, and specifically targeting <canvas>: drawables, my other work has been largely based on a open source client side templating engine by Beebole calledPURE. For those of you looking to entirely replace server side rendering you can do no better!

But ultimately, I see HTML5 moving typical development closer to Flash than ever before. Moreover you can already create HTML5 apps that work much the same way as Flash using <object data="my.HTML"> to embed the other document within you current document on the server side without an iframe!

There are some important things to note about using object embedding in this way. First off, each document has it's own JS context, and communication between them requires using a messaging subsystem. More over, neither environment can manipulate the DOM of the other. This makes serving untrusted content and code inline "safe" ( for certain values of safe as there is a bug in Andoid that exposes too much info to embedded contexts).

What this means for web frameworks is that it is possible to compose a page entirely of <object> tags which include components from other sources, each encapsulated in their own JS and DOM context. This allows developers to stop worrying about political problems like how best to use the global namespace, or which JS framework gets to own $, and start building a page out of truly relocatable and reusable components.

How I envision Phos application development to work is a base system image will be included on the page with a script tag, and the world definition encapsulated in an <object> tag that embeds the view manifest, a list of objects to instantiate into the view. The Phos in the top level document will then instantiate a separate context for each remote component defined in the manifest. Allowing for the construction of multiple independent applications in a single page context.

The parent Window object works as a messaging hub to allow worlds to communicate with each other. This is tivial to implement and fast. When combined with the existing event system, it is also 100% transparent to the programmer.

The next major release of Phos will also have this sort of tooling built to the point where one can build components, wire up, andd program directly. With the Stuff transport mechanism it will be trivial to share and embed these Phos worlds in any other HTML page as well.

And that is how it will become a real web framework.