New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fluxury

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fluxury

Add luxury sugar to simplify implementing Facebook's flavor of Flux architecture.

  • 0.2.13
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
decreased by-80.36%
Maintainers
1
Weekly downloads
 
Created
Source

fluxury

Circle CI

Add sugar to Facebook's implementation of Flux architecture. It adds a little luxury to simplify your life.

This library is similar to Reflux and Redux except that this library doesn't try to replace the dispatcher with a new implementation. The library encourages you into simple patterns but doesn't try to change the core concepts.

This library is an opinionated set of functions that allow you to easily define actions and stores; and dispatch actions to these stores.

This new "Flux framework" adds a surface area of 3 functions.

API

  1. Fluxury.dispatch( type, data )
Submit an action into the stores. You must specify the type and, optionally, some data.
```js
Fluxury.dispatch('REQUEST_SETTINGS')
// or with data
Fluxury.dispatch('LOAD_SETTINGS', { a: 1, b: 2 })
```

2. Fluxury.createActions(action1, action2, ..., actionN)

Create your actions from a list of strings as `arguments`.

_MyActions.js_
```js
export default Fluxury.createActions('INC', 'DEC', 'SET')
```

This returns a key mirrored object.

```js
{
  INC: 'INC',
  DEC: 'DEC',
  SET: 'SET'
}
```

To use the action in a React component:

```js
import {INC} from './MyActions'

var React = require('react');
var Fluxury = require('fluxury');
var PropTypes = React.PropTypes;

var MyComponent = React.createClass({

  handleClick: function() {
    /* Call dispatch to submit the action to the stores */
    Fluxury.dispatch(INC)
  }

  render: function() {
    return (
      <button onClick={this.handleClick}>+1</button>
    );
  }

});

module.exports = MyComponent;

```

3. Fluxury.createStore(name, initialState, reducer)

Create a new store with a name and a reducer.

```js
import {INC} from './MyActions'
export default Fluxury.createStore('CountStore', 0, function(state, action) {
  if (action.type === INC) {
    return state + 1;
  }
  return state;
})
```

Perhaps you prefer the class switch case:

```js
import {INC} from './MyActions'
export default Fluxury.createStore('CountStore', 0, (state, action) => {
  switch (action.type)
  case INC:
    return state + 1;
  default:
    return state;
})
```

In this example you can make them both disappear:

```js
import {INC} from './MyActions'
export default Fluxury.createStore('CountStore', 0, function(state, action) {
    return state + (action.type === INC ? 1 : 0);
})
```

As previously discovered by many the reducer pattern remains a powerful tool.

MapStore Example

For simple projects with limited datasets you may be best suited to use a single store for the entire application. After all, you can nest the object as deeply as needed to organize and isolate your data.

var Fluxury = require('fluxury');

// no need for Fluxury.createActions when you have a single action!
var SET = 'SET';

var store = Fluxury.createStore('MapStore', {}, function(state, action) {
  switch (action.type) {
    case SET:
      return Object.assign(state, action.data)
    default:
      return state;
  }
});

Fluxury.dispatch(SET, { states: ['CA', 'OR', 'WA'] })
// store.getState() => { states: ['CA', 'OR', 'WA']  }

Fluxury.dispatch(SET, { selectedState: 'CA' })
// store.getState() => { states: ['CA', 'OR', 'WA'], selectedState: 'CA' }

FAQs

Package last updated on 12 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc