@codecademy/fluxile

1.0.2 • Public • Published

Drawing


Fluxile is a set of mixins (and more, eventually) that enhance the Reflux flux library (though it could potentially be used with a different flux implementation);

Installing:

npm install @codecademy/fluxile --save

Statemixin.store

import { createStore } from 'reflux';
import { StateMixin } from 'fluxile';

export const MyStore = createStore({
  mixins: [StateMixin.store],

  getInitialState() {
   return {
     items: [
      {
        title: 'First Item',
        body: 'Lorem ipsum'
      }
     ],
     currentItemIndex: 0
   }
  }
});

StateMixin.connect

Listen to a single key on a store:

import React, { createClass } from 'react';
import { StateMixin } from 'fluxile';
import MyStore from './store/MyStore';

export const MyComponent = createClass({
  mixins: [StateMixin.connect(MyStore, 'items')],

  render() {
    return (
      <div>
        {this.state.items.map((itm) => <div>{item.title}</div>)}
      </div>
    )
  }

});

Listen to multiple keys on a store:

import React, { createClass } from 'react';
import { StateMixin } from 'fluxile';
import MyStore from './store/MyStore';

export const MyComponent = createClass({
  mixins: [StateMixin.connect(MyStore, ['items', 'currentItemIndex'])],

  render() {
    return (
      <div>
        {
          this.state.items.map((itm, i) => {
            <div className={(i === this.state.currentItemIndex) 'current' : ''}>
              {item.title}
            </div>
          });
        }
      </div>
    )
  }

});

connect (as function)

import React, { Component, PropTypes} from 'react';
import { connect } from 'fluxile';
import MyStore from './store/MyStore';

class MyComponent extends Component {

  static propTypes = {
    items: PropTypes.array
  };

  render() {
    return (
      <div>
        {this.props.items.map((itm) => <div>{item.title}</div>)}
      </div>
    )
  }

};

export default connect(MyStore, ['items'])(MyComponent)

connect (as es7 decorator)

import React, { Component, PropTypes} from 'react';
import { connect } from 'fluxile';
import MyStore from './store/MyStore';

@connect(MyStore, ['items'])
class MyComponent extends Component {

  static propTypes = {
    items: PropTypes.array
  };

  render() {
    return (
      <div>
        {this.props.items.map((itm) => <div>{item.title}</div>)}
      </div>
    )
  }

};

export default MyComponent;

connect (as function with multiple stores)

import React, { Component, PropTypes} from 'react';
import { connect, compose } from 'fluxile';
import MyStore from './store/MyStore';
import MyOtherStore from './store/MyStore';

class MyComponent extends Component {

  static propTypes = {
    items: PropTypes.array
  };

  render() {
    return (
      <div>
        {this.props.items.map((itm) => <div>{item.title}</div>)}
      </div>
    )
  }

};

export default connect(MyStore, ['items'])(MyComponent)

Circle CI

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.21latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.21
1.0.1126
1.0.01
0.8.11
0.8.01
0.7.01
0.6.01
0.5.10
0.5.00
0.4.00
0.3.00
0.2.00
0.1.00
0.0.10

Package Sidebar

Install

npm i @codecademy/fluxile

Weekly Downloads

132

Version

1.0.2

License

MIT

Unpacked Size

28.5 kB

Total Files

18

Last publish

Collaborators

  • codecademy