RingoJS

18
RingoJS #cgnjs talk by Oleg Podsechin 12.10.2010

description

My talk talk on RingoJS, a CommonJS-compliant JavaScript platform.

Transcript of RingoJS

Page 1: RingoJS

RingoJS

#cgnjs talk by Oleg Podsechin

12.10.2010

Page 2: RingoJS
Page 3: RingoJS

Install & Run

apt-get install default-jdk default-jre git-core ant

git clone git://github.com/ringo/ringojs.gitant jarbin/ringo

Page 4: RingoJS

Hello World

>> 'Hello World'Hello World

Page 5: RingoJS

Hello World, Take Two

new (require('ringo/httpserver').Server)({  app: function() {    return {status: 200,             headers: {},             body: ['Hello World']};  }}).start();

Page 6: RingoJS

RingoJS overview

• started by @hannesw (hns.github.com)• uses Mozilla Rhino• runs on the JVM• successor to Helma, HelmaNG• been in development for 10+ years• conforms to CommonJS

Page 7: RingoJS

CommonJS support

• Modules/1.0, Modules/1.1• JSGI• Binary• Filesystem• System• Unit Testing

• other (mostly partial) implementations include: Akshell, CouchDB, Flusspferd, Narwhal, Persevere, RequireJS, Smart, SproutCore, node.js, v8cgi etc.

Page 8: RingoJS

RingoJS features #1

• REPL• hot reloading of modules• profiler• debugger• ringo-admin tool• runs anywhere, including AppEngine• client side CommonJS modules via ringo-modulr

• JMX

Page 9: RingoJS

RingoJS features #2

• JavaScript 1.8• Java library wrapping• runs sync and async code• continuations• introspection (via Rhino)

• middleware• templating• utils• persistence abstraction layer

Page 10: RingoJS

jsonp-proxy.js #1// thanks to @jasondaviesvar {encode} = require('ringo/base64'),    {get} = require('ringo/httpclient'),    {Request} = require('ringo/webapp/request'),    {ByteString} = require('binary');

exports.app = function(env) {    var req = new Request(env);    var url = req.params.url, raw = get(url);    return {        status: 200,        headers: {'Content-Type': 'text/javascript'},        body: [req.params.callback +            '("data:"+decodeURIComponent("' +            encodeURIComponent(raw.type) +            '")+";base64,',           encode(new ByteString(raw.content)),            '")']    };}

Page 11: RingoJS

jsonp-proxy.js #2Usage:

$.get('http://seivadnosaj-js.appspot.com/proxy', {  url: 'http://www.jasondavies.com/media/img/jason.jpg'}, function(data) {  var img = new Image();  img.onload = function() {    var w = img.width, h = img.height;    $('#canvas').attr('width', w).attr('height', h);    context.width = w; context.height = h;    context.drawImage(img, 0, 0, w, h);  };  img.src = data;}, 'jsonp');

Try it at: http://seivadnosaj-js.appspot.com/

Page 12: RingoJS

Multithreaded JS (sort of)

// run "test" in "threads" parallel threads a total of "count" timesfunction parallel(test, count, threads) {  var pool = new java.util.concurrent.Executors.newFixedThreadPool(threads);

  function runnable(f) {    return new java.lang.Runnable({ run: function() {      try { f(); } catch(e) { }    }});  }

  for(var i = 0; i < count; i ++)    pool.execute(runnable(test));}

Page 13: RingoJS

Debugger

Page 14: RingoJS

Ride - web IDE

Page 15: RingoJS

RingoJS libraries

• search GitHub for ringo-• ringo-admin install user/repo

Page 16: RingoJS

RingoJS performance

Page 17: RingoJS

RingoJS community

• active & friendly

• #ringojs on Freenode IRC• #ringojs & @ringojs on Twitter• http://github.com/ringo

Page 18: RingoJS

Questions? Comments?

@olegpodsechin