flight-tower

A collection of Flight components and mixins that aids in communicating with backend services using XHR requests


License
MIT
Install
bower install flight-tower

Documentation

flight-tower

Build Status Coverage Status

A collection of Flight mixins that aids in communicating with backend services.

Installation

bower install --save flight-tower

Mixins

withAjax

This mixin will emit life cycle and success/fail events for an ajax request.

API

  • get(url, eventName[, data])
  • post(url, data, eventName)
  • ajax(url, ajaxOptons, eventName)
  • redoRequest(failData) - will try for redoRetries times max, default 10.

.get/.post are both thin wrappers around .ajax which in turn is a thin wrapper around $.ajax`.

All methods returns the jQuery promise from $.ajax in case you want to add your own callback to the mix.

Events

All events are created out of the eventName you pass in. The examples all use the event Example.

The event names are based off of the suggested naming conventions in Getting Started with Twitter Flight.

All:

  • dataExample - a successful request
  • dataExampleFail - a failed request

dataExampleFail will trigger with the data to reproduce the request as well as status and response from the server.

GET/HEAD events:

  • fetchExampleStart
  • fetchExampleEnd

POST/PUT/PATCH events (any other than get/head):

  • submitExampleStart
  • submitExampleEnd

Example

define(function(require) {
    var defineComponent = require('flight/lib/component'),
        withAjax = require('flight-tower/lib/with_ajax');

    return defineComponent(formData, withAjax);

    function formData() {
        this.defaultAttrs({
            redoRetries: 10
        });

        this.after('initialize', function() {
            this.get('/some-data', 'Countries');
            this.post('/submit', {user: 'test', password: 1234}, 'UserLogin');
            this.ajax('/submit', {data: {user: 'test', password: 1234}}, 'UserLogin');
        });
    }
});

Development

Development of this component requires Bower to be globally installed:

npm install -g bower

Then install the Node.js and client-side dependencies by running the following commands in the repo's root directory.

npm install & bower install

To continuously run the tests in Chrome during development, just run:

npm run watch-test

Contributing to this project

Anyone and everyone is welcome to contribute. Please take a moment to review the guidelines for contributing.