"Flight is a lightweight, component-based JavaScript framework that maps behavior to DOM nodes. Twitter uses it [...you're not even reading this far.]" - flightjs.github.io
But I'm a fan of [ , , , , , whatever ] framework!
I think a lot of frameworks are over-used and shoehorned into projects where they aren't the best tool for the job.
I question the work-to-reward ratio of a lot of today's front-end frameworks
Instead of asking 'how is Y framework like [my favorite],' we should ask 'how will this make my JS better?'
(Later. Over food or a beer.)
Definition of the word 'framework':
"an essential supporting structure of a building, vehicle, or object."
-Merriam-Webster
You can follow along at GitHub
Count: <span class="js-count"></span>
<a class="btn btn-success js-increment" href="" target="_blank"></a>
<a class="btn btn-danger js-decrement" href="" target="_blank">-</a>
function counter() {
this.attributes({
'counterDisplay': '.js-count',
'incrementButton': '.js-increment',
'decrementButton': '.js-decrement'
});
this.after('initialize', function () {
this.select('counterDisplay').text('0');
this.on('click', {
'incrementButton': this.increment,
'decrementButton': this.decrement
});
this.on('counterChange', this.change);
});
//...event handlers after this...
}
return defineComponent(
withMixin1,
withMixin2,
withMixin3,
componentConstructor);
define(function(require){
var myCounter = require('components/counter');
myCounter.attachTo('.js-counter', {
//you can override attributes here.
});
})
We can now override our selectors without changing the class. We have made our component markup agnostic.
This gives us a large chunk of the code reusability that we normally don't get.
Cute Critters as Components
this.on('toy_falls', this.omg);
this.after('initialize', function(){
this.on('friend_lick', this.nope);
})
this.nope = function(){
this.push();
this.cleanSelf();
}
//...some other code...
try{
this.weirdFunction();
} catch (e) {
$(this).trigger('weirdError', {
error: e
});
}
//...our component...
this.after('intiialize', function(){
this.on('weirdError', this.panic);
});
Flight provides all the utilites you need to write testable client-side JS
beforeEach(function () {
setupComponent('<span class="js-counter"></span><span class="js-increment"></span>');
});
it('should fire a counterChange with 1 when the increment button is clicked',
function(){
var eventSpy = spyOnEvent(document, 'counterChange');
this.component.select('incrementButton').click();
expect(eventSpy).toHaveBeenTriggeredOn(document);
expect(eventSpy.mostRecentCall.data).toEqual({ value: 1 });
});
Not only does Flight give you the tools, it encourages you to write testable code.
That's OK. Flight plays well with other libraries. Or maybe Flight isn't the solution. Use the right tool for the job.
The super-secret super-complicated very-difficult omg-halp plan to mix Flight code into your codebase
(And you should totally <3 it, too.)
Flight is a framework that allows you to structure your app without intimidating and confusing your newer devs.
Save yourself from absolute chaos, and relegate yourself to the normal level of chaos.
Because developer hapiness is contagious!
http://github.com/kperch/midwest_js
@nodebotanist
kas@nodebots.io