|
JooseOnGears
How Joose and Google Gears can work together
IntroductionJoose supports several ways to work with Google Gears out of the box. Whenever possible the APIs are implemented in a way that they automatically fall back to alternatives when a user does not have Gears installed. In particular the following APIs are directly supported: DatabaseThe Joose distribution includes an object-relational mapper that enables transparent access to the Google Gears database and the HTML5 database (which is currently primarily supported by the Safari browser). You'll find it the examples directory under examples/simple_orm/async and you can try it out with this demo application. Declaring a database entity class looks like this: Class("Person", {
isa: ORM.Entity,
tableName: "person",
hasOne: {
mother: {
isa: function () { return m.Person }
}
},
hasMany: {
cars: {
isa: function () { return m.Car },
foreignKey: "owner"
}
}
});The OR-Mapper will use the native HTML5 database if available and use the Gears database as a fallback. If neither is available it will throw an exception. The OR-Mapper is currently under heavy-development. For more info, check out this series of blog posts. You are encouraged to try it out. Simply checkout the latest Joose version from svn. LinksWorkerPoolYou can automatically execute methods of a Joose.Class in a different thread using Google Gears. All you need to do is to use the meta class Joose.Gears and add a worker method. All the Gears-Interfacing is handled for you. If Gears is not present, the worker is executed in the main thread. The workers result will be sent to a method called "on"+uppercaseFirst($worker_name) if available: Class("HardWork", {
meta: Joose.Gears,
has: {
data: {is: rw, init: {}}
},
methods: {
onDoWork: function (result) {
ok(result == 1001, "Gear Worker returns correct result")
}
},
workers: {
doWork: function (start) {
var counter = start;
for(var i = 0; i < 1000; i++) {
counter++
}
return counter
}
}
})
var hw = new HardWork();
hw.doWork(1)If Gears is not available, the method will simply be executed in the main thread. LinksHttpRequestJoose includes a simple helper method to do AJAX-requests that automatically use the Google Gears HTTP-Request-API if available which can greatly enhance the performance of pages which make heavy use of AJAX. Just call Joose.Gears.ajaxRequest(method, url, data, callback) to initiate a request, where
If Gears is not available, the system will perform a regular AJAX request. |
Sign in to add a comment
really, a wonderful innovation by google. nice!
Apart from gears support.....how different is it from something like Dojo?
Joose is really a new way to do object-oriented development with JavaScript. When you use a pure-DOM-interface library like jQuery, Joose is a great fit to write your JS classes that use jQuery to work with the browser. Dojo has a wider scope (DOM library + component framework) than pure DOM manipulation libraries but it is still possible to use Joose in conjunction with Dojo.