Skip to content

Instantly share code, notes, and snippets.

Avatar

Jed Schmidt jed

View GitHub Profile
View fab.template.js
// this is an example of what the first pass at native (fab) templates will look like:
with ( require( "fab" ) ) fab
( listen, 0xFAB )
( /\// )
( /1/ )
( "This is a template with no variables: a unary app" )
View fab.template_comma.js
// the upcoming (fab) rewrite is also sympathetic to folks that don't care for parentheses:
with ( require( "fab" ) ) fab
( listen, 0xFAB
, /\//
, /1/
, "This is a template with no variables: a unary app"
View fab-next.md

changes coming in (fab) v0.5.0

here's a quick outline of some of the stuff i'm working on in the next release of (fab). once i have the internals working again, i'll push a branch for folks to play with.

100% async

right now, (fab) is mostly async, but relies on sync in one case: apps need to return a listener if they require more information to finish. this is a problem because apps may not know if they need more information until they hear from their upstream apps.

for example, a template app needs to return a function based on a string, but that string may come from an async file or http request, so the app can't reliably respond immediately.

View fab.arity.js
// async: manually sets the length of a function by wrapping it in another with the desired length
fab.arity = function( num ) {
var fn = function(_){ fn.apply( this, arguments ) }
, ends = [ "this(", ")" ]
, args = [];
while ( --num ) args[ num - 1 ] = "_" + num;
this( Function( "fn", ends.join( fn ).replace( "_", args ) ) );
View nextfab.js
require( "fab" )
( "hello, {{1}}!" )
( "world" )
[ "call" ]
( function( app ) { module.exports = app } )
View fab-next-addenda.md

an update on fab v0.5

hey all, sorry for the lack of pushes this past week, but i'm still chugging on the v0.5 branch locally. here's an update of two changes i've made.

removed dependence on function length

this was a bit of a hard decision to make, but i've decided to stop using the function length property to differentiate unary apps from n-ary apps. it was a cute hack, but it needs to go for two reasons:

  • the google closure compiler doesn't respect argument count during compression. it removes any unused trailing arguments, which can end up changing the length of a function. this isn't too important now, but will be once (fab) starts moving client-ward.
View npm.txt
e0109-119-107-225-189:cookie-node jed$ sudo npm install .
npm configfile /Users/jed/.npmrc
npm sudo true
npm cli [ 'install', '.' ]
npm install pkg .
npm install local .
npm readJson package.json
npm testEngine required: node ""
npm packTar . /Users/jed/.node_libraries/.npm/.cache/cookie/v0.1.0/package.tgz
npm exec tar "czf" "/Users/jed/.node_libraries/.npm/.cache/cookie/v0.1.0/package.tgz" "--exclude" ".git" "cookie-node"
View puts.js
puts = require( "sys" ).puts;
puts( "puts" );
puts( "puts" );
puts( "puts" );
require( "repl" ).start();
puts( "puts" );
puts( "puts" );
View meh.js
var body = "Hello World"
, http = require( "http" )
, puts = require( "sys" ).puts
, connect = require( "./Connect/lib/connect" )
, jsgiNode = require( "./jsgi-node" )
, fab = require( "fab_old" )
, connectMiddleware = {
View context_vs_argument.js
var puts = require( "sys" ).puts
, contextFn = function( a ){ return a && this() }
, argFn = function( a, b ){ return b && a() }
, time;
time = +new Date;
for ( var i = 0; i < 10e6; i++ ) contextFn.call( contextFn, contextFn );
puts( "as context: " + ( +new Date - time ) );
time = +new Date;