Asynchronous 如何@连接到异步加载的数据?
我正在用React、Redux、React-Redux、React-router、React-router-Redux和Redux-async-connect编写一个应用程序。该应用程序的特殊之处在于,所有客户机-服务器通信都是通过WebSocket完成的 我的用户可以读/写几面墙,我存储的是一个Asynchronous 如何@连接到异步加载的数据?,asynchronous,reactjs,redux,react-redux,Asynchronous,Reactjs,Redux,React Redux,我正在用React、Redux、React-Redux、React-router、React-router-Redux和Redux-async-connect编写一个应用程序。该应用程序的特殊之处在于,所有客户机-服务器通信都是通过WebSocket完成的 我的用户可以读/写几面墙,我存储的是一个walls存储,具有以下减速器和基本辅助功能: const LOAD = 'ws/wall/LOAD'; const LOAD_SUCCESS = 'estisia/wall/LOAD_SUCCESS'
walls
存储,具有以下减速器和基本辅助功能:
const LOAD = 'ws/wall/LOAD';
const LOAD_SUCCESS = 'estisia/wall/LOAD_SUCCESS';
const LOAD_FAIL = 'estisia/wall/LOAD_FAIL';
const ADD_MESSAGE = 'estisia/wall/ADD_MESSAGE';
const initialWallState = {
loaded: false,
messages: []
};
const initialState = {
walls: {}
};
function wall(state = initialWallState, action = {}) {
switch (action.type) {
... // omitted for brevity
default:
return state;
}
}
export default function walls(state = initialState, action = {}) {
if (typeof action.data === 'undefined' || typeof action.data.wallId === 'undefined') return state;
const newState = {
...state.walls,
[action.data.wallId]: wall(state.walls[action.data.wallId], action)
};
return {walls: newState};
}
export function isLoaded(wallId, globalState) {
return globalState.walls.wallId && globalState.walls.wallId.loaded;
}
export function load(wallId) {
return {
type: LOAD,
send: ['wall/messages/page', [wallId, 1]]
};
}
我有一个Wall
容器,其中相应的wallId
由react路由器传入,但不知道如何使@connect
调用只将相关的Wall数据传递给容器。我应该做什么来代替下面的@connect元代码来让它工作呢
@asyncConnect([{
deferred: true,
promise: ({store: {dispatch, getState}, params}) => {
if (!isLoaded(params.wallId, getState())) {
return dispatch(loadWall(params.wallId));
}
}
}])
@connect(
state => ({
messages: state.wall[this.params.wallId].messages,
loading: state.wall[this.params.wallId].loading
}))
export default class Wall extends Component {
static propTypes = {
messages: PropTypes.array
}
... // omitted for brevity
}
我如何实现
redux async connect
来帮助我解决上述问题?在@connect
方法中,您希望从哪里获得this.params.wallId
?在@connect
方法中,您希望从哪里获得this.params.wallId
?