Web Info & Tutorials

January 18th, 2008

NATIVE COMET SUPPORT FOR BROWSERS

As JavaScript developers, we are used to years of hacks, as we try to push forward without browsers updating and helping us out. We are so stuck in this pragmatic thinking that we sometimes forget to pick our heads up.

Kris Zyp has taken some time to think about Comet, and instead of thinking about the next good hack, he takes that step back and dreams:

What if I had commit privileges on all the major browsers, the competence to add functionality in all the code bases, and wanted to add native Comet support in a form that was easily accessible to developers?

He ends up with a proposal that adds to good ole XHR:

With only a few simple XMLHttpRequest API additions, Comet communication could be realized with a native implementation that supports fast and efficient standards-based two-way asynchronous communication, with true server-delivered HTTP streaming and simple subscription requests, with the added benefit of client-delivered streaming and cached resource until updated capability. Developers could create Comet applications with a standard API without hacks. Communication could be standards-based, allowing current servers to easily implement the necessary features to handle communication.

It would look something like this:

JAVASCRIPT:
  1.  
  2. var cometXHR = new XMLHttpRequest;
  3. cometXHR.open('POST','comet',true);
  4.  
  5. var xhr1 = new XMLHttpRequest;
  6. cometXHR.addHttpChunk(xhr1);
  7. xhr1.onreadystatechange=function(){...}
  8. xhr.open('GET','/ticker1',true);
  9. xhr.send();
  10.  
  11. var xhr2 = new XMLHttpRequest;
  12. cometXHR.addHttpChunk(xhr2);
  13. xhr2.onreadystatechange=function(){...}
  14. xhr.open('GET','/ticker2',true);
  15. xhr.send();
  16.  

Kris gets into many of the details, and makes me with that someone would implement this as a Google Gear, so it could get pushed into the fabric of the Web by being on all browsers.

January 18th, 2008

JSONLIB: JSON EXTENSIONS A LA E4X

Nicholas C. Zakas wanted to keep JSON out of JavaScript. He has patterned a new form of JSON support on E4X and wrote it up.

Nichole wants:

  • The addition of two new global types: JSON and JSONList. JSON represents a JSON object while JSONList represents a JSON array.
  • Both types have a toJSONString() method that correctly encodes an object into a JSON string. The default toString() method is available but returns a string representation of the object (not a JSON string). This follows the convention set forth in E4X.
  • The [[Put]] method is overridden in both types such that it will only accept values of type JSON, JSONList, Date, boolean, string, number, or null. Any other data types cause an error to be thrown.
  • The JSON constructor allows an object to be passed in that has initial properties to add; the JSONList constructor allows an array to be passed in with items to add.
  • The typeof operator should return "json" when used on a value of type JSON or JSONList.
  • JSON strings are parsed via JSON.parse(), throwing syntax errors if they are found.

You can see it in action:

JAVASCRIPT:
  1.  
  2. var obj = JSON.parse("{\"name\":\"Nicholas\",\"age\":29}");
  3.  
  4. var json = new JSON();
  5. json.put("name", "Nicholas");
  6. json.put("age", 29);
  7. var name = json.get("name");
  8. var str = json.toJSONString();
  9.  
  10. var list = new JSONList();
  11. list.put(0, "blah");
  12. list.push(25);
  13. list.push(true);
  14. var val = list.get(1);
  15. var len = list.getLength();
  16. var str = list.toJSONString();
  17.  
  18. var json = new JSON({name:"Nicholas"});
  19. var name = json.get("name");
  20.  

Summary

It is slightly more verbose than the current methods for using JSON in JavaScript, however, I believe this solution keeps JSON out of the core of JavaScript and maintains useful access to JSON parsing and serialization. The key to understanding this approach is that JSON and JSONList are purely data storage objects without any additional functionality. They have one job and they do it well. Make sure you only use put() or other methods to add values to the objects instead of just assigning new properties.

January 18th, 2008

ECLIPSE RAP DEMONSTRATION

Back in Oct we discussed the newborn Eclipse RAP agency that tries to alter OSGi to the client.

Michael Coté of Redmonk interviewed Jochen Krause to handle RAP, and exhibit covering utilization in action:

In this digit conception screencast, Jochen Krause and I speech most the Eclipse Rich Ajax Platform, or RAP for short. RAP is a front-end support that uses the Eclipse RCP planning help to create Ajax front-ends in Java. In the prototypal part, Jochen gives us an overview of RAP and how it fits into the coverall Eclipse runtime and then shows a some demos of using RAP in the ordinal part.

January 18th, 2008

AMALTAS SVG DRAWING TOOL

Amaltas Bohra has created a drawing/editing agency that allows you to create ultimate shapes and pictures.

The covering uses SVG to do its work, and Prototype to appendage the Ajaxyness.

Amaltas SVG