novajs

14
Nova @WeAreFractal @NodeAZ

Upload: wearefractal

Post on 19-Jun-2015

436 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Novajs

Nova

@WeAreFractal@NodeAZ

Page 2: Novajs

Inspiration

● Lots of great NodeJS libraries we want to use on the client● Writing NodeJS code > writing browser code● Seemed like fun● Kind sir at the Adobe group said it couldn't be done.

Page 3: Novajs

Goals

● Map as much NodeJS functionality to the browser as we possibly can● Keep the syntax/usage the same● Keep it tiny, keep it simple● Don't use any external dependencies – too lame, we keep it sikk● Hot interface for building your packages● Needs to be extremely easy to extend and use with existing libraries● ABSOLUTELY MUST be compatible with UselessJS (50% done)

Page 4: Novajs

Limitations

● Initiating P2P outbound connections – IMPOSSIBLE (kind of)● System interactions can only be emulated at best● HTML5 localStorage limits – 5MB or less● JS vs. Native speed – not too slick

Page 5: Novajs

require('fs');

● File reads – Attempts HTML5 localStorage, defaults to AJAX● File writes – HTML5 localStorage● Mock file system is set up within HTML5 localStorage to emulate folder and file properties● File watching and events done using localStorage events● Syntax identical to NodeJS

● Progress: 50%

Page 6: Novajs

require('events');

● EventEmitter operates the same as it's NodeJS counterpart● Sugar and new functionality (wildcards, namespacing, etc.) to be added

● Progress: 100%

Page 7: Novajs

require('assert');

● AssertionError thrown on failure● Operates the same as it's NodeJS counterpart● Used to test itself – Microsoft approved

● Progress: 100%

Page 8: Novajs

TODO

● require('sys') – 100%● require('util') – 99%● require('readline') – 50%● require('http') – 25% (Rewriting native parsers in JS = fail)● require('os') – 75% (Needs more efficient detection methods)

Page 9: Novajs

require('3rd-party');

● require('es5-shim') - magically make everything work on older browsers● require('jquery') - 229kb of fun● require('zepto') - jQuery with the fat sucked out

● Adding existing libraries to nova is extremely simple

Page 10: Novajs

Cool story bro

● Microlib compilers are nothing new (Ender)● require() in the browser is nothing new (brequire, requirejs)

Page 11: Novajs

NOPE

● RequireJS is super-optimized but modules are nothing like NodeJS modules● Ender simply doesn't have enough libraries to do what we want● NodeJS in the browser hasn't been done before (hopefully)

require.config({ baseUrl: require.isBrowser ? "./" : "./exports/"});

require(["require", "vanilla", "funcSet", "assign", "assign2"], function (require, vanilla, funcSet, assign, assign2) { doh.register("exports", [ function exports(t) { //Use the imports }]); doh.run();});

Page 12: Novajs

NATIVE CODE – HOPE!

● Chromium Native Client allows you to access native code in the browser● Native client gives us unlimited storage and a sandboxed file system● Wrapping native libraries like zlib and more can be simplified● May allow us to run standard NodeJS libraries without modification

Page 13: Novajs

Size

● Nova Core (All NodeJS libs) is currently 4.3k minified, 1.1k gzipped● Adding DOM manipulation and networking modules only bumps it to 5.4k/1.7k● You can pick and choose modules – your size may vary.

Page 14: Novajs

return;

@WeAreFractalCode: http://github.com/wearefractal/novaDocs: http://wearefractal.github.com/nova

0.0.3 will be released tonight (hopefully)