novajs
Post on 19-Jun-2015
436 Views
Preview:
TRANSCRIPT
Nova
@WeAreFractal@NodeAZ
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.
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)
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
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%
require('events');
● EventEmitter operates the same as it's NodeJS counterpart● Sugar and new functionality (wildcards, namespacing, etc.) to be added
● Progress: 100%
require('assert');
● AssertionError thrown on failure● Operates the same as it's NodeJS counterpart● Used to test itself – Microsoft approved
● Progress: 100%
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)
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
Cool story bro
● Microlib compilers are nothing new (Ender)● require() in the browser is nothing new (brequire, requirejs)
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();});
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
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.
return;
@WeAreFractalCode: http://github.com/wearefractal/novaDocs: http://wearefractal.github.com/nova
0.0.3 will be released tonight (hopefully)
top related