indexzero
2/25/2012 - 6:29 AM

THE FRAMEWORK YOUR FRAMEWORK COULD CODE LIKE

THE FRAMEWORK YOUR FRAMEWORK COULD CODE LIKE

exports.attach = function (opts) {
  opts = opts || {};

  var that = this;

  this.qty = opts.qty || 2;
  this.description = opts.description || 'that thing you love';

  this.redeem = function () {
    console.log('You go to see ' + that.description + ' and it\'s SPECTACULAR.');
    that.qty--;
  };

}
22:18 josh@onix /tmp/old-spice
% node app.js
What's that in your hand? Look down,
look up. I HAVE IT. It's 2 TICKETS to that thing you love!
Look again.
THE TICKETS ARE NOW DIAMONDS
* bling *
* bling *
* bling *
* bling *
* bling *
* bling *
Anything is possible when you use flatiron and stop using express.
I'm on a horse.
* bling *
22:21 josh@onix /tmp/old-spice
% 
exports.attach = function () {
  var sparkling = false;

  this.sparkle = function sparkle () {
    sparkling = true;

    setTimeout(function () {
      console.log('* bling *');

      if (sparkling) {
        sparkle();
      }

    }, 2000 * Math.random());
  };

  this.stopSparkling = function () {
    sparkling = false;
  };

}
var flatiron = require('flatiron'),
    app = flatiron.app;

console.log('What\'s that in your hand? Look down,');
app.use(require('./tickets'));

console.log('look up. I HAVE IT. It\'s ' + app.qty + ' TICKETS to ' + app.description + '!');

console.log('Look again.');
app.use(require('./diamonds'));

console.log('THE TICKETS ARE NOW DIAMONDS');
app.sparkle();

setTimeout(function () {

  app.stopSparkling();

  console.log('Anything is possible when you use flatiron and stop using express.');
  console.log('I\'m on a horse.');
}, 6000);