Home

Awesome

<img src="logo.png?raw=true&amp;v=2" width="375" height="128" alt="lux.js: Illuminating React" />

What Is It

lux.js is an implementation of a Flux architecture using ReactJS, postal.js and machina.js. In a nutshell, the React components, dispatcher and stores are highly de-coupled. Here's a gist of the opinions at play:

* Due to not forcing immutable objects, its possible to change state via reference, but the Store apis encourage explicitly getting and setting state and the setState helper is only functional in a store's action handler.

Example Usage

This is a very simple example showing a single store and a lux wrapped component. You can play with this example online.

store.js

import { Store } from "lux.js";

export default new Store( {
	namespace: "light",
	state: {
		light: "off"
	},
	handlers: {
		"toggleLight"() {
			const { light } = this.getState();
			this.setState( {
				light: light === "off" ? "on" : "off"
			} );
		}
	},
	getLightStatus() {
		return this.getState().light;
	}
} );

LightMode.js

import React from "react";
import { luxWrapper, dispatch } from "lux.js";
import lightStore from "./store";

function LightMode({ lightStatus, onToggleLight }) {
	return (
		<div>
			<p>
				Light Status: <b>{lightStatus}</b>
			</p>
			<div className={`light light-${lightStatus}`}>
				<i className="fa fa-lightbulb fa-3x" />
			</div>
			<button onClick={onToggleLight}>Toggle Light</button>
		</div>
	);
}

export default luxWrapper(LightMode, {
	stores: ["light"],
	getState() {
		return {
			lightStatus: lightStore.getLightStatus()
		};
	},
	actions: {
		onToggleLight() {
			dispatch("toggleLight");
		}
	}
});

Development

To build the project:

$ npm install
$ npm run build

Built files appear under /lib in the project root.

To run tests:

npm test

Examples and More: