1.0.2 • Published 4 years ago

@codecademy/fluxile v1.0.2

Weekly downloads
461
License
MIT
Repository
github
Last release
4 years ago

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

1.0.2

4 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.8.1

8 years ago

0.8.0

8 years ago

0.7.0

8 years ago

0.6.0

10 years ago

0.5.1

10 years ago

0.5.0

10 years ago

0.4.0

10 years ago

0.3.0

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago

0.0.1

10 years ago