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 🙏

© 2025 – Pkg Stats / Ryan Hefner

relax.js

v0.2.2

Published

An imlementation of the Flux pattern

Downloads

36

Readme

Relax.js

This is a tiny, framework agnostic implementation of the Flux pattern inspired by the DeLorean, but closer to the original Facebook approach with data incapsulation.

Relax doesn't force you to use any additional conventions. It just gives you an ability to move on without writing too much boilerplate code. Since Relax Dispatcher uses Facebook Dispatcher you can access original methods though Relax provide you bunch of more convenient wrappers for them.

It is highly recommended to use it with the Facebook Immutable library for more Store data privacy.

Installation

Using Node Package Manager:

npm install relax.js --save

Using Bower:

bower install relax.js --save

Examples

You can check the TodoMVC example on http://127.0.0.1:1337 after executing

grunt todomvc

Note: Example uses ECMAScript 2015 syntax.

Usage

First of all let's create a simple Dispatcher.

// AppDispatcher.js

module.exports = Relax.createDispatcher();

If you don't want to create Actions module, you don't have to. Just use handleViewAction and handleServerAction Dispatcher methods.

// SomeActions.js

var AppDispatcher = require('./AppDispatcher');

module.exports = {
    append: function (data) {
        /**
        * An actionType have to be same as a key of the object
        * passed to Dispatcher.subscribe() method.
        */
        AppDispatcher.handleViewAction(
            actionType: 'appendData',
            data: data
        );
    }
};

Then, make a simple Store with just one action.

Note: The return value for the data modification function have to be a boolean value which indicates whether Store emits change event or not.

// SomeStore.js

var AppDispatcher = require('./AppDispatcher');

var collection = [];

function appendData(data, source) {
    /** 
    * Source parameter corresponds to Relax.VIEW_ACTION or Relax.SERVER_ACTION
    * it depends on usage of Dispatcher.handleViewAction() or Dispatcher.handleServerAction()
    */
    switch (source) {
        case Relax.VIEW_ACTION:
            // code
            break;
        case Relax.SERVER_ACTION:
            //code
            break;
    }
    
    /**
    * Data parameter corresponds to the data of an action
    * passed to Dispatcher.handleViewAction() or Dispatcher.handleServerAction()
    */
    collection.push(data);

    return true; // Return value here indicates whether Store emits change event or not
}

var SomeStore = Relax.createStore({
    getAll: function () {
        return collection;
    }
});

/**
* Keys for second parameter are actionTypes of the actions
* passed to Dispatcher.handleViewAction() aor Dispatcher.hnadleServerAction()
*/
AppDispatcher.subscribe(SomeStore, {
    'appendData': appendData
});

module.exports = SomeStore;

Now we can create a simple view to close the Flux cycle.

// SomeView.js

var SomeStore = require('./SomeStore');
var SomeActions = require('./SomeActions');

function storeDidChange() {
    var collection = SomeStore.getAll();

    // Any rendering process here
}

function onAnyElementClick(e) {
    var data;

    // extract data from the view

    SomeActions.append(data);
}

SomeStore.onChange(storeDidChange);

// Some more logic...

SomeStore.offChange(storeDidChange);

Tests

npm test

Note: Tests for now are under development.

License

Relax.js is MIT-licensed.