Neurological Phenomenon Multiplexer
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    flux-queue-dispatcherpublic

    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.

    install

    npm i flux-queue-dispatcher

    Downloadsweekly downloads

    31

    version

    0.1.3

    license

    ISC

    repository

    githubgithub

    last publish

    collaborators

    • avatar