Skip to content

Instantly share code, notes, and snippets.

@jfhbrook
Created February 25, 2012 06:22
Show Gist options
  • Save jfhbrook/1906886 to your computer and use it in GitHub Desktop.
Save jfhbrook/1906886 to your computer and use it in GitHub Desktop.
THE FRAMEWORK YOUR FRAMEWORK COULD CODE LIKE
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();
}, 6000);
app.on('sparkling::done', function () {
console.log('Anything is possible when you use flatiron and stop using express.');
console.log('I\'m on a horse.');
});
exports.attach = function () {
var sparkling = false;
var that = this;
this.sparkle = function sparkle () {
sparkling = true;
setTimeout(function () {
console.log('* bling *');
if (sparkling) {
sparkle();
}
else {
that.emit('sparkling::done');
}
}, 2000 * Math.random());
};
this.stopSparkling = function () {
sparkling = false;
};
}
22:35 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 *
* bling *
* bling *
* bling *
Anything is possible when you use flatiron and stop using express.
I'm on a horse.
22:35 josh@onix /tmp/old-spice
%
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--;
};
}
Copy link

ghost commented Feb 25, 2012

devil's advocatingly, with express you could do something like:

var diamonds = require('./diamonds.js');
app.use(diamonds);
diamonds.sparkle();
setTimeout(function () { diamonds.stopSparkling() }, 6000);

I'm not sure how applicable that approach would be to flatiron but it seems like a better way of organizing functionality since everything isn't glued onto the app object.

@jfhbrook
Copy link
Author

How would this work though? I mean, what's the point of doing an express app.use if you're not handling any http requests? Flatiron stock is basically just an IoC container with some utility functions strapped on unless you app.use(flatiron.plugins.http).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment