npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fluxible-action-utils

v0.2.4

Published

utility methods to aid in writing actions for fluxible based applications.

Downloads

117

Readme

fluxible-action-utils

npm version Build Status Dependency Status devDependency Status Coverage Status

Join the chat at https://gitter.im/yahoo/fluxible-action-utils

Utility methods to aid in writing actions for fluxible based applications.

$ npm install --save fluxible-action-utils

Modularized Builds/Requires

The utility library provides modularized methods, and method categories to aid in providing smaller browserify and webpack builds.

var actionUtils = require('fluxible-action-utils');

Will require the entire library, including all available methods grouped under their respective method categories.

For example, the following are equivalent (but will result in varying sized webpack builds)

Full Library (results in largest build)

var executeMultiple = require('fluxible-action-utils').async.executeMultiple;

Category

var executeMultiple = require('fluxible-action-utils/async').executeMultiple;

Method (results in smallest build)

var executeMultiple = require('fluxible-action-utils/async/executeMultiple');

:rotating_light: WARNING :rotating_light:

Methods inside the internals directory/category are not explicitely exported and are considered unstable.

require externally at your own risk as breaking changes inside internals will not be considered breaking for the library.

===

API

===

async

available as of v0.2.0

var asyncActionUtils = require('fluxible-action-utils/async');

Methods grouped under the async category are concerned with providing methods that aid in managing the asynchronous control flow of fluxible actions.

run-auto is used under the hood to do the actual heavy lifting (thanks to @feross)

executeMultiple (context, actions, [done])

available as of v0.2.0

var executeMultiple = require('fluxible-action-utils/async/executeMultiple');

Utility method used to execute multiple actions in parallel where possible. Each key in actions represents a task to be executed (and should be unique).

actions[task] can be one of the following

  1. {FluxAction} an action to be executed, cannot be critical nor require params
  2. {Object} an action "object" with the follwing properties
    1. action {FluxAction} the action to execute
    2. [isCritical=false] {Boolean} whether the action is critical
    3. [params] {Any} parameters to pass to the action when executing it
  3. {Array} {String, String, ..., FluxAction|Object} array which defines the tasks/actions that need to be executed before executing the action of type 1. or 2. found at the end of the array.

The done {Function} parameter is optional, but if provided, will be called when all tasks complete (either with success or failure). Signature function (err, results)

For each task that fails, the error returned will be aggregated under err[task].

Example

// initHome.js

var executeMultiple = require('fluxible-action-utils/async/executeMultiple');
var UserStore = require('app/stores/UserStore');

module.exports = function initHome(context, params, done) {
    executeMultiple(context, {
        loadUH: require('UH').actions.load,
        loadUser: {
            action: require('app/actions/loadUser'),
            isCritical: true
        },
        loadStuffForUser: [
            'loadUser',
            {
                // will be executed after 'loadUser' task completes successfully
                action: require('../../actions/loadStuffForUser'),
                params: context.getStore(UserStore).getGUID()
            }
        ],
        populateUserNotifications: [
            'loadUH',
            'loadStuffForUser',

            // will be executed after the 'loadUH' and 'loadStuffForUser' tasks complete successfully
            require('../../actions/populateUserNotifications')
        ]
    }, function (err, results) {
        // there was at least one error, handle them
        if (err) {
            if (err.loadUser) {
                context.dispatch('CATASTROPHE', err.loadUser);
            }

            if(err.loadStuffForUser) {
                context.dispatch('RECOVERABLE', err.loadStuffForUser);
            }
            done();
            return;
        }
        // Yay! no errors
        // ...
        done();
    });
};

executeCritical (context, actions, [done])

available as of v0.2.0

var executeCritical = require('fluxible-action-utils/async/executeCritical');

executeCritical allows you to execute a group of actions that are ALL deemed critical. This is a simple shorthand for executeMultiple when a group of actions are all critical.

mixins

available as of v0.2.0

var mixins = require('fluxible-action-utils/mixins');

Mixins grouped under the mixins category are concerned with providing React component mixins that simplify using fluxible actions.

PeriodicActions

available as of v0.2.0

var PeriodicActionsMixin = require('fluxible-action-utils/mixins/PeriodicActions');

Utility mixin used to make running an action repeatedly (polling an API for example) easier to do.

You can either write code using the methods exposed by the mixin directly, or you can use the statics support.

uuid must be a unique identifier, attempting to add another action with the same uuid as a currently running periodic action will fail to add.

Statics Example

// MyReactComponent.jsx

var PeriodicActionsMixin = require('fluxible-action-utils/mixins/PeriodicActions');
var myPollingAction = require('./myPollingAction');

// Let's say you have a child component that implement the controlling logic for the polling action below
var ControlComponent = require('./someControlComponent');

module.exports = React.createClass({
    displayName: 'MyReactComponent',
    mixins: [PeriodicActionsMixin],
    statics: {
        periodicActions: [
            {
                uuid: 'MY_UNIQUE_POLLING_ACTION_UUID_STATICS',
                action: myPollingAction,
                // Optional params
                params: {
                    customPayload: 'payload'
                },
                // Optional timeout (Defaults to 100 ms)
                timeout: 1000
            }
        ]
    },
    render: function () {
        // You can pass the auto-binded component methods to the child component to achieve
        // custom timing on the dedicated action(s)
        return <ControlComponent
                    startPolling={this.startPeriodicActions}
                    stopPolling={this.stopPeriodicActions}
               />;
    }
});

Code Example

// MyReactComponent.jsx

var PeriodicActionsMixin = require('fluxible-action-utils/mixins/PeriodicActions');
var myPollingAction = require('./myPollingAction');

module.exports = React.createClass({
    displayName: 'MyReactComponent',
    mixins: [PeriodicActionsMixin],
    componentDidMount: function () {
        this.startPeriodicAction(
            'MY_UNIQUE_POLLING_ACTION_UUID_CODE',
            myPollingAction,
            // Optional params
            {customPayload: 'payload'},
            // Optional timeout (Defaults to 100 ms)
            1000
        );
    },
    /* Don't need this, all periodic actions will be stopped automatically on unmount
    componentWillUnmount: function () {
        this.stopPeriodicAction('MY_UNIQUE_POLLING_ACTION_UUID_CODE');
    },
    */
    render: function () {
        return null;
    }
});

FAQ

Thanks

License

This software is free to use under the Yahoo Inc. BSD license. See the LICENSE file for license text and copyright information.