nl-flux

raw JSON →
1.1.10 verified Fri May 01 auth: no javascript

An ES6 Flux library for ReactJS, providing a Flux dispatcher and Store base class with an immutable state tree. Version 1.1.10 (latest stable) includes core Flux and Store exports, plus sessionStorage helpers. The library emphasizes an Action-on-Store pattern with Immutable.js state management, offering event listeners on store updates. Requires Immutable.js as a peer dependency. Compared to alternatives like Redux, nl-flux is more opinionated and tightly coupled with Immutable.js, making it suitable for projects already using Immutable. Releases appear infrequent; check for compatibility with newer React versions.

error TypeError: flux.getStore is not a function
cause Flux.getStore is the correct method; ensure you import Flux correctly and it is not shadowed.
fix
Use 'import { Flux } from 'nl-flux'' and then 'Flux.getStore('storeName')'.
error Store is not a constructor
cause Store is a named export, not a default export.
fix
Use 'import { Store } from 'nl-flux'' instead of 'import Store from 'nl-flux''.
error Cannot read property 'toJS' of undefined
cause getStore returned undefined because the store name is incorrect or not registered.
fix
Check that the store is registered with Flux.registerStore(MyStore) and use the same name in getStore (defaults to class name).
gotcha Flux.getStore('storeName') assumes store is registered with that name (the class name). If not, it may return undefined.
fix Ensure the store class is registered via Flux.registerStore and the name matches the class name used in getStore.
gotcha onAction switch must return new state or the same state. Not returning a value may lead to unexpected behavior.
fix Always return state in each case of onAction, even if no change: return state.
breaking Immutable.js v4 changed Map API (e.g., fromJS). Older versions may fail with nl-flux.
fix Ensure immutable version is compatible; test with immutable@3.x if issues arise.
npm install nl-flux
yarn add nl-flux
pnpm add nl-flux

Demonstrates creating a Store with initial state, handling actions via onAction, registering with Flux, dispatching an action, and reading the immutable state tree.

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

class AppStore extends Store {
  initialState() {
    return { count: 0 };
  }

  onAction(type, data, state) {
    switch (type) {
      case 'INCREMENT':
        return state.update('count', v => v + 1);
      default:
        return state;
    }
  }
}

const store = Flux.registerStore(AppStore);

Flux.dispatch({ type: 'INCREMENT' });
console.log(Flux.getStore('AppStore').toJS()); // { count: 1 }