使用“反应路由器-DOM”:“^ 4.1.2”,“反应路由器 - 终极版”:“^ 5.0.0-alpha.6 “我得到按标题‘遗漏的类型错误:无法读取属性‘类型’的未定义在执行console.log阵营路由器终极版’()重定向后瞬间完成。 截图显示它不是用行动观察到的包含有效载荷数据的问题。有效载荷包含表单数据(值)和历史记录对象。 我设法给他们,然后通过使用mergeMap代替ES6地图,因为我处理的观测量递归函数的方法捕捉它们。 link to the repo遗漏的类型错误:无法读取属性“类型”的不确定阵营路由器终极版
import * as ActionTypes from "../ActionTypes";
import { createPostFulfilled, fetchPosts, fetchPostsFulfilled, fetchPostsWithIdFulfilled, changeRoute } from "../actions";
import {store, history} from "../configureStore";
import { Observable } from "rxjs/Observable";
import "rxjs/add/observable/combineLatest";
import "rxjs/add/operator/debounceTime";
import { concat as concat$ } from "rxjs/observable/concat";
import { from as from$ } from "rxjs/observable/from";
import { of as of$ } from "rxjs/observable/of";
import "rxjs/add/operator/map";
import "rxjs/add/operator/mergeMap";
import "rxjs/add/operator/startWith";
import "rxjs/add/operator/filter";
import "rxjs/add/operator/switchMap";
import "rxjs/add/operator/concatMap";
import "rxjs/add/operator/catch";
import "rxjs/add/observable/dom/ajax";
import {push} from "react-router-redux";
const ROOT_URL = "http://reduxblog.herokuapp.com/api";
const API_KEY = "key=davide123";
export const fetchPostsEpic = (action$) => {
return action$.filter((action$)=> action$.type === ActionTypes.FETCH_POSTS)
.mergeMap(action$ => {
return Observable.ajax.getJSON(`${ROOT_URL}/posts/?${API_KEY}`)
.map(response => fetchPostsFulfilled(response), (err) => {console.log(err);});
});
};
export const fetchPostsWithIdEpic = (action$) => {
return action$.filter((action$)=> action$.type === ActionTypes.FETCH_POSTS_WITH_ID)
.mergeMap(action$ => {
return Observable.ajax.getJSON(`${ROOT_URL}/posts/?${action$.payload}&${API_KEY}`)
.map(response => fetchPostsWithIdFulfilled(response), (err) => {console.log(err);});
});
};
export const createPostEpic = (action$) => {
const actionVectorizer = ((action$) => {
if (action$)
return action$.isArray() ? [].concat(...action$.mergeMap(x => actionVectorizer(x))) : action$;
})();
return action$.filter((action$)=> action$.type === ActionTypes.CREATE_POST)
.mergeMap(action$ => {
console.log("action$ is...");
console.log(action$);
let { values, history } = action$.payload;
return Observable.ajax.post(`${ROOT_URL}/posts/?${API_KEY}`, values)
.map(
(data) => {
if (data.status === 201) {
console.log("Success status", data.status);
history.push("/");
// return createPostFulfilled(data.status);
}
else {console.log("Server error is", data.status);}
},
(err) => {console.log(err);}
);
});
};
谢谢@jayphelps,我对此表示赞赏。 –
@DavidePugliese不客气!如果合适,请将其标记为已接受的答案。 – jayphelps