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

react-fluxit

v0.1.0

Published

A Flux implementation for use with React

Downloads

4

Readme

Fluxit

A simple implementation of React's Flux architecture.

Dispatcher

The dispatcher manages all data flow in a Flux application - its only function is to distribute the action data to the stores which have registered with it.

Stores

In a Flux application, stores are responsible for managing the application's data and state. A store will typically be responsible for a particular domain in the application.

Store are updated as a result of data dispatched from actions and will emit change events to any listeners. They register with the dispatcher to signal their interest in receving action data. Stores may provide an API for reading data but should not expose methods to update data directly.

Actions

Actions are invoked to start the flow of data in the application, either as the result of user interaction or a web API call. In the React Flux documentation, there is a distinction between Action and ActionCreator while in Fluxit, it is simplified to Action. An action is simply a function which takes a data object with a type and payload.

The action will dispatch the data to all registered stores by invoking the dispatcher.

Note that an action may also perform additional operations on the data by calling web APIs before dispatching the data.

Getting Started

    var Fluxit = require('fluxit');
    Fluxit.initialize();
Creating a Dispatcher

Fluxit provides a default dispatcher but a custom Dispatcher can be specified: in Fluxit.initialize:

    Fluxit.initialize({
        dispatcher: // dispatcher implementation
    });

When Fluxit is initialized it will set the default dispatcher for both stores and actions by calling Store.setDispatcher and Action.setDispatcher.

The Fluxit dispatcher can be accessed using Fluxit.getDispatcher

A dispatcher can be created using Fluxit.Dispatcher:

var AppDispatcher = new Fluxit.Dispatcher();

Creating Stores

Use Store.create:

    var Store = Fluxit.Store;
    var AppStore = Store.create({
        displayName: 'AppStore',
        actions: {
            'ACTION_TYPE': 'handleAction'
        },
        handleAction: function(action) {
            // update store state based on action and notifiy listeners of change
            this.sendChange();
        }
    );
    // create an AppStore instance and specify options
    // options can be accessed in the store's action handlers with `this._options`
    var apps = new AppStore({});

The displayName property identifies the store and is used when registering a store with the dispatcher property identifies the store and is used when registering a store with the dispatcher.

The actions property defines what actions the store will handle when dispatched. The handler can be a function or a string identifying the store's method to call. Note that all handlers are called with the store as the this argument.

Alternatively, you can specify your own initialize method for the store and call onAction to register action callbacks:

    var Store = Fluxit.Store;
    var AppStore = Store.create({
        displayName: 'AppStore',
        initialize: {
            // ... perform store specific initialization
            this.onAction('ACTION_TYPE, 'handleAction')
            .onAction('SOME_OTHER_ACTION_TYPE', 'handleSomeOtherAction')
            // or use a map
            this.onAction({
              'ACTION_TYPE': 'handleAction',
              'SOME_OTHER_ACTION':  'handleSomeOtherAction'
            });
        },
        handleAction: function(action) {
            // update store state based on action and notifiy listeners of change
            this.sendChange();
        },
        handleSomeOtherAction: function(action) {
            // ...
        }
    );

Actions

Fluxit provides a base action implementation:

    var Action = Fluxit.Action;

    // use the default dispatcher configured through Fluxit.initialize
    var appAction = Action.create(function(data) {
        this.dispatchAction('ACTION_TYPE', data);
    });

    // create multiple actions
    var actions = Action.create({
        save: function(data)  {
            // ...
        },
        update: function(data) {
            // ...
        }
    });

The Action implementation also provides a dispatchError method to signal errors as a result of calling an action:

    var appAction = Action.create(function(data) {
        // ... do something with data that may result in an error
        this.dispatchError('ACTION_TYPE', err);
    });

The action data will have the following properties:

  • error - true to indicate the action resulted in an error
  • cause - the cause of the error, e.g. an exception that was thrown