Skip to content
Jichao Ouyang edited this page Feb 26, 2016 · 8 revisions

API

connect

connect(dataFlow:func [, props]):function

props is optional, it will become default props of Component connect returned

connect return a fucntion, which you can apply to Component later.

example:

    import {connect} from 'react-most'

    class TodoItem extends React.Component {
      ...
    }
    export default connect(function(intent$){
 intent$.filter(...).map(....)
...
})(TodoItem)

data flow

data flow is user define flow for intent stream, must return a object contains actions and sinks

let RxCounter = connect(function(intent$){
  let defaultState$ = most.of(_=>({value:0}))
  let addSink$ = intent$.filter(x=>x.type=='add').map(({increment})=>state=>({value: state.value+increment}))
  return {
    add: increment=>({type: 'add', increment}),
    defaultState$,
    addSink$,
  }
})(Counter);

sinks are Stream, action will be called whenever you wan to send something into Intent Stream.

History

connect(intent$=>[awesome flow], {history:true})(App)

once you connect history to App, you have two extract methods from props

  1. props.history.backward
  2. props.history.forward

wrapper

wrapper wrap you App, so it can provide actions, and setState for you. new state will pass to you App via props. you don't have to care about state then, only to compose a clean data flow.

import Most from 'react-most'
<Most>
  <Counter />
</Most>

Reactive engine [experimental]

if you are Rx user, optionally you can pass a engine props into Most.

import Most from 'react-most'
<Most engine={function rxify() {
  let addToIntentStream = subject.onNext;
  let intentStream = new Rx.Subject();

  function flatObserve(intentSinks, f){
    return Rx.Observable.from(intentSinks).mergeAll().observe(f);
  }
  return {intentStream, addToIntentStream, flatObserve}
}}>
  <Counter />
</Most>

other reactive lib user can easily proivde you favor engine by simply provide these 3 things:

  1. intentStream: a Steam contains intents
  2. historyStream: a Stream contains history
  3. flatObserve(sinks,func): flat Stream of Stream sinks, and observe with func.
Clone this wiki locally