0.1.3 • Published 8 years ago

flux-queue-dispatcher v0.1.3

Weekly downloads
11
License
ISC
Repository
github
Last release
8 years ago

Flux dispatcher with queued actions

Build status

Implements the Flux dispatcher with queued actions.

Motivation

The basic implementation prevents us from running dispatch() while dispatching. However, if dispatch() is triggered by, for example, an AJAX request, we can't guarantee it is not called during a dispatch.

To handle this situation all dispatch() calls are put into a queue and executed sequentially.

Usage

Set up the dispatcher module.

// @file /dispatcher.js
import QueueDispatcher from 'flux-queue-dispatcher';

var dispatcher = new QueueDispatcher();
export default dispatcher;
export const dispatch = dispatcher.queueDispatch.bind(dispatcher);

Use it whenever actions are triggered.

// @file /comp1.js
import React from 'react';
import {dispatch} from './dispatcher.js';

class Comp1 extends React.Component {
    _event() {
        // Make asynchornous dispatch
        setTimeout(function() {
            dispatch({
                type: 'action1'
            });
        }, 100);
        // The time of the callback execution is unknown
        $.get('/data', function(result) {
            dispatch({
                type: 'action2',
                payload: result
            });
        });
    }
    render() {
        return <a click={this._event}>Click me!</a>;
    }
}
export default Comp1;

Read more about the Flux dispatcher.

0.1.3

8 years ago

0.1.2

8 years ago

0.1.0

8 years ago