我使用react native,redux和redux-observables(使用rxjs5),并发出ajax请求。问题是当发生错误时我无法返回动作。
这是我的代码:
var horizontalConstraint1 = NSLayoutConstraint()
var horizontalConstraint2 = NSLayoutConstraint()
var verticalConstraint1 = NSLayoutConstraint()
var verticalConstraintOuter = NSLayoutConstraint()
horizontalConstraint1 = v.leadingAnchor.constraint(equalTo: (v.superview?.leadingAnchor)!,constant:10)
horizontalConstraint2 = v.trailingAnchor.constraint(equalTo: (v.superview?.trailingAnchor)!,constant:-10)
if self.prevView == nil{
verticalConstraint1 = v.topAnchor.constraint(equalTo: (v.superview?.topAnchor)!, constant: 0)
NSLayoutConstraint.activate([horizontalConstraint1,horizontalConstraint2,verticalConstraint1 ])
}else {
if let pv = self.prevView as? UIView {
verticalConstraint1 = v.topAnchor.constraint(equalTo: (pv.bottomAnchor), constant: 10)
verticalConstraintOuter = v.topAnchor.constraint(equalTo: (v.superview?.topAnchor)!,constant:10 )
verticalConstraintOuter.priority = UILayoutPriority(rawValue: 800)
NSLayoutConstraint.activate([horizontalConstraint1,horizontalConstraint2,verticalConstraint1,verticalConstraintOuter])
}
}
self.prevView = v

显然,问题在于这一行:
//action creators
export const loginSucceeded = token => {
return {
type: Types.LOGIN_SUCCEEDED,
payload: {
token
}
};
};
export const login = (username, password) => {
return {
type: Types.LOGIN,
pauload: {
username,
password
}
};
};
export const loginFailed = () => {
return {
type: Types.LOGIN_FAILED
};
};
//epic
const authEpic = (action$, store$) =>
action$.ofType(Types.LOGIN).mergeMap(action => {
const authBody = {..};
const headers = {..};
return ajax
.post(API.LOGIN, authBody, headers)
.map(result => {
return Actions.loginSucceeded(result.response.access_token);
})
.catch(err => {
return Actions.loginFailed();
});
});
如果我更改它以返回每个句子,我仍然会得到相同的错误
return Observable.of(Actions.loginFailed());

这是错误:
Observable.of(Actions.loginFailed);
Observable.of(Actions.loginFailed());
Actions.loginFailed;
Actions.loginFailed();

我阅读了很多关于它的StackOverflow问题,但几乎所有问题都有错误的函数调用,而且没有一个应用于我的问题或处理我的问题。