RingoJS
-
Upload
oleg-podsechin -
Category
Technology
-
view
3.819 -
download
1
description
Transcript of RingoJS
RingoJS
#cgnjs talk by Oleg Podsechin
12.10.2010
Install & Run
apt-get install default-jdk default-jre git-core ant
git clone git://github.com/ringo/ringojs.gitant jarbin/ringo
Hello World
>> 'Hello World'Hello World
Hello World, Take Two
new (require('ringo/httpserver').Server)({ app: function() { return {status: 200, headers: {}, body: ['Hello World']}; }}).start();
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
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.
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
RingoJS features #2
• JavaScript 1.8• Java library wrapping• runs sync and async code• continuations• introspection (via Rhino)
• middleware• templating• utils• persistence abstraction layer
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)), '")'] };}
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/
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));}
Debugger
Ride - web IDE
RingoJS libraries
• search GitHub for ringo-• ringo-admin install user/repo
RingoJS performance
RingoJS community
• active & friendly
• #ringojs on Freenode IRC• #ringojs & @ringojs on Twitter• http://github.com/ringo
Questions? Comments?
@olegpodsechin