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

easyflux

v0.1.4

Published

Easy, straight to the point events

Downloads

11

Readme

Easyflux Build Status

How to get it

npm install easyflux --save
bower install easyflux --save

A bit of intro

I'm well aware that at this point, the interwebs is full of solutions, for every particular issue, there is. Lately, React from Facebook emerged, and it brought a full spectrum of issues. First there's Flux. Hard to get, use and start going. Then there was Reflux, a nice clean way of using Flux principles. Still, in my mind, something was missing: easy to use events.

I don't want to gave in an use some sort of frontend API to simply store data, and respond to changes(Flux) I need more. I need to be able to couple/decouple the events based on my needs.

Enter Easyflux.

What is this?

Basically, creates buckets of events, that you can use. I've seen something similar in Reflux, but not powerful enough.


    var globalEvents = Easyflux([
        'resetData',
        'login',
        'logout'
    ]);
    
    // Later in code
    // Listening for login
    globalEvents.login.listen(callbackFunction, context);
    
    // Triggering the login
    globalEvents.login.trigger(data);

Now, apply this to React.

React usage

Maybe the above syntax, did not convince you, hopefully this will.


    // Our dull, isolated component
    var MyComponent = React.createClass({
    
        events: Easyflux([
            'change'
        ]),
    
        getInitialState: function() {
            return {
                data: 'Initial data'
            }
        },
        
        componentDidMount: function() {
        
            // On change event, change the message
            this.events.change.listen(function(newData) {
                this.setState({
                    data: newData
                });
            }, this);
        },
        
        render: function() {
            return <span className="custom-text">{this.state.data}</span>
        }
    
    });
    
    [...]
    
    // Later in our App
    var App = React.createClass({
        
        componentDidMount: function() {
        
            // Change the text in our isolated component
            this.refs.statusText.events.change.trigger('App has loaded');
        },
        
        render: function() {
            return <MyComponent ref="statusText"/>
        }
    
    });

That line, though, it's a bit hard to write. Below, it's using the Easyflux.Mixin


    // Our dull, isolated component
    var MyComponent = React.createClass({
    
        mixins: [Easyflux.Mixin],
    
        events: Easyflux([
            'change'
        ]),
    
        getInitialState: function() {
            return {
                data: 'Initial data'
            }
        },
        
        componentDidMount: function() {
        
            // On change event, change the message
            this.listenTo('change', function(newData) {
                this.setState({
                    data: newData
                });
            }, this);
        },
        
        render: function() {
            return <span className="custom-text">{this.state.data}</span>
        }
    
    });
    
    [...]
    
    // Later in our App
    var App = React.createClass({
        
        componentDidMount: function() {
        
            // Exactly, Backbone-style method prints
            this.refs.statusText.trigger('change', 'App has loaded');
        },
        
        render: function() {
            return <MyComponent ref="statusText"/>
        }
    
    });

Proper scoping the events

At some point you'll end up having difficulties between listening to children events, that are scoped to their own namespace and context. Take a look at the demo. You can pass to children an events object, with 'eventName': this._onEventName defined keys. This will be triggered whenever the internal event is triggered inside that children. Pretty useful stuff!


    // JSX
    render: function() {
        return <MySuperReusableComponent events={{ 'change': this._onChangeEvent, 'doesSomething': this._onDoesSomething }} />
    }
    
    // JS
    render: function() {
        return React.createElement(MySuperReusableComponent, {
            events: {
                'change': this._onChangeEvent,
                'doesSomething': this._onDoesSomething
            }
        });
    }

Final thoughts

This should be treated as a simple solution for multi-directional events.

Feedback

Given that this tries to introduce a simpler way, of listening to events, any feedback is gratefully received.