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

nl-flux

v1.1.10

Published

An ES6 Flux library for ReactJS

Downloads

46

Readme

NL Flux

An ES6 Flux library that includes:

  • Flux
  • Store

Installation

Using npm:

$ npm install nl-flux

###App Usage Then with a module bundler like webpack that supports either CommonJS or ES2015 modules, use as you would anything else:

// Using an ES6 transpiler for web apps
import {Flux, Store} from 'nl-flux';

// not using an ES6 transpiler
var Flux = require('nl-flux').Flux;
var Store = require('nl-flux').Store;

How to use

A complete example can be found in the nl-react-skeleton. Below is an example of an action and a store.

Store:

import {Flux, Store} from 'nl-flux';
import {Map} from 'immutable';

class App extends Store {
  initialState() {
    return {
      test: 'default'
    };
  }

  onAction(type, data, state) {
    switch(type) {
      case 'APP_TEST':
        return state.set('test', data.demo);
      case 'APP_RESET':
        return Map(this.initialState());
      default:
        return state;
    }
  }
}

export default Flux.registerStore(App);

Action:

import {Flux} from 'nl-flux';

const AppActions = {
  test: (str) => {
    Flux.dispatch({type: 'APP_TEST', demo: str});
  }
};

export default AppActions;

Component:

import React, {Component} from 'react';
import {Flux} from '../flux';

// Enable console debugger
Flux.enableDebugger();

export default class AppView extends Component {
  constructor(props) {
    super(props);
    
    // Initial state
    this.state = {
      myTest: ''
    };

    // Bind methods
    this.onAppTest = this.onAppTest.bind(this);
  }
  
  componentWillMount() {
    // Add listeners
    Flux.on('APP_TEST', this.onAppTest);
    
    // Initialize
    AppActions.test('Hello World');
  }

  componentWillUnmount() {
    Flux.off('APP_TEST', this.onAppTest);
  }
  
  onAppTest() {
    // Gets the immutable store
    const myTest = Flux.getStore(['app', 'test']);
    
    // Show the output in the console
    console.log('onAppTest::myTest', myTest);
    
    // Set state to re-render component
    this.setState({myTest});
  }
  
  render() {
    return <div>{this.state.myTest}</div>
  }
};

export default AppActions;

API

on(eventType, data)

Adds an event listener. It is called any time an action is dispatched to Flux, and some part of the state tree may potentially have changed. You may then call getStore() to read the current state tree inside the callback.

Arguments

  • [eventType] (String): Event to subscribe for store updates.
  • [listener] (Function): The callback to be invoked any time an action has been dispatched.

off()

Removes the event listener.

  • [eventType] (String): Event to unsubscribe.
  • [listener] (Function): The callback associated with the subscribed event.

dispatch(action)

Dispatches an Action to all stores

  • [action] (Object): An action object. The only required property is type which will indicate what is called in the stores, all other properties will be sent to the store within the data object.

getStore(name)

Get the state tree. If only a particular store is needed, it can be specified.

  • [name] (String): (optional) A store name.

getClass(name)

Get the store class object.

  • [name] (String): Name of the store class.

registerStore(Class)

Registers the store with Flux.

  • [Class] (Class): The store class.

#####Returns

A new object from the class. This is usually exported at the end of the store class.

deregisterStore(name)

Unregisters the store with Flux.

  • [name] (String): Name of store to remove from Flux.

getSessionData(key)

Get an object from sessionStorage.

  • [key] (String): Key of object to retrieve.

#####Returns

An Immutable object or a string.

setSessionData(key, value)

Save an object to sessionStorage.

  • [key] (String): Key to reference object.
  • [value] (String|Object|Immutable): A string or object to save. Immutable objects will be converted to JSON. All objects will converted to a string before saving.

delSessionData(key)

Remove an object from sessionStorage.

  • [key] (String): Key of object to delete.

getLocalData(key)

Get an object from localStorage.

  • [key] (String): Key of object to retrieve.

#####Returns

An Immutable object or a string.

setLocalData(key, value)

Save an object to localStorage.

  • [key] (String): Key to reference object.
  • [value] (String|Object|Immutable): A string or object to save. Immutable objects will be converted to JSON. All objects will converted to a string before saving.

delLocalData(key)

Remove an object from localStorage.

  • [key] (String): Key of the object to remove.

enableDebugger()

Turn on the console debugger to display each action call and store changes.