0.2.2 • Published 7 years ago

react-rx-actions v0.2.2

Weekly downloads
7
License
MIT
Repository
github
Last release
7 years ago

React Rx Actions

Seperate UI and Business logic using an unidirectional data-flow.

Business logic in Rx

import { Action$, toReact } from 'react-rx-actions';

// Step 1. Listen to the Action$
Action$
  .ofType('LOGIN')
  .map(function(){
    /* do stuff */
    return { name: 'Mark', role: 'Admin'}
  })
  // Step 2. Publish data to React
  .map(user => ({ user }))
  .do(toReact('user'))

UI in React

import { createContainer, dispatch } from 'react-rx-actions';

// In your component
class MyComponent() extends Component {
  // Step 3. Render your data in react
  render() {
    <div>Current user: { this.props.user.name }</div>;
  }  

  // Step 4. Dispatch actions, goto step 1
  onLoginClick(){
    dispatch('LOGIN', {username: '...', password: '...' })
  }
}

export default createContainer(['user'])(MyComponent)
0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago