2017-09-25 6 views
0

さまざまなコンポーネントをt-reduxで管理されている状態に接続する必要がありますが、t-reduxはreducerといくつかの初期状態を受け入れるだけのwithState()関数しか持たないようです。したがって、すべてのコンポーネントは「新しい状態」を受け取っているようです。t-reduxライブラリに、reduxの公式接続関数のように機能する関数はありますか?

ライブラリは、これが一つです:あなたは、各高次成分が含まれていることを、あなたが表示されますT-再来のwithStateの実装を見てみるとこれが公式の例

// import the needed modules 
import {withState, dispatcher, buildReducer} from 't-redux' 


// this is a PORC (Plain Old React Component) 
class MyCounter extends React.Component { 
    constructor() { 
    super() 
    this.plusOne = this.plusOne.bind(this) 
    } 
    plusOne() { 
    // Dispacth the action (the content is optional) 
    dispatcher.dispatch({type: 'PLUS_ONE', content: this.props.counter}) 
    } 
    render() { 
    return (
     <div> 
     <div>Click count: {this.props.counter}</div> 
     <button onClick={this.plusOne}>Add 1</button> 
     </div>) 
    }  
} 
// Build the reducers as a map ACTION:(state, action) => state 
const reducers = buildReducer({ 
    'PLUS_ONE': (state, action) => ({counter: state.counter + 1}) 
}) 

// Define the initial state 
const INITIAL_STATE = { counter: 0 } 

// export the wrapped component passing the reducers and the initial state 
export default withState([reducers], INITIAL_STATE)(MyCounter) 

答えて

0

あるhttps://www.npmjs.com/package/t-redux

その自分の状態。具体的なセグメントは以下の通りです:

constructor(props) { 
    super(props) 
    this.state = { innerState: initialState } 
    } 

componentWillMount() { 
    this.regId = dispatcher.register(action => { 
    const nextState = combineReducers(reducers, this.state.innerState, action) 
    this.setState({innerState: nextState}) 
    }) 
} 

componentWillUnmount() { 
    dispatcher.unregister(this.regId) 
} 

本質的に、それはレフィックスパターンの状態を格納するためにリアクトのコンポーネント状態を使用しています。このように実装されているため、すべてのコンポーネントに対して単一のストアを持つ方法はありません。

+0

ありがとうございました。私はt-redux哲学を誤解しました。 –

関連する問題