Redux传奇和immutablejs
我已经使用redux、redux saga和immutable js创建了一个基本的授权流 Redux表单(v6.0.0-rc.4)允许表单创建不可变映射。我将这些值传递给redux saga,在那里我将尝试将这些值传递给我的登录函数 问题1:从概念上讲,何时是使用Redux传奇和immutablejs,redux,immutable.js,redux-saga,Redux,Immutable.js,Redux Saga,我已经使用redux、redux saga和immutable js创建了一个基本的授权流 Redux表单(v6.0.0-rc.4)允许表单创建不可变映射。我将这些值传递给redux saga,在那里我将尝试将这些值传递给我的登录函数 问题1:从概念上讲,何时是使用值的适当时间。get('username')访问不可变映射中的数据?在我的故事里,在功能上?我应该等到最后一步才提取值吗 问题2:假设我能够在正确的位置提取值,我不确定该如何在传奇中处理这个问题-这是我的loginFlow传奇: ex
值的适当时间。get('username')
访问不可变映射中的数据?在我的故事里,在功能上?我应该等到最后一步才提取值吗
问题2:假设我能够在正确的位置提取值,我不确定该如何在传奇中处理这个问题-这是我的loginFlow传奇:
export function* loginFlow(data) {
while (true) {
yield take(LOGIN_REQUEST);
const winner = yield race({
auth: call(authorize, { data, isRegistering: false }),
logout: take(LOGOUT),
});
if (winner.auth) {
yield put({ type: SET_AUTH, newAuthState: true });
forwardTo('/account');
} else if (winner.logout) {
yield put({ type: SET_AUTH, newAuthState: false });
yield call(logout);
forwardTo('/');
}
}
}
数据
是redux表单的不可变映射。然而,每当我在我的传奇中记录数据时,它只会返回0
显然我没有正确处理将不可变映射传递到操作的操作-正确的代码:
export function* loginFlow() {
while (true) {
// this line ensures that the payload from the action
// is correctly passed through the saga
const { data } = yield take(LOGIN_REQUEST);
const winner = yield race({
// this line passes the payload to the login/auth action
auth: call(authorize, { data, isRegistering: false }),
logout: take(LOGOUT),
});
if (winner.auth) {
yield put({ type: SET_AUTH, newAuthState: true });
forwardTo('/account');
} else if (winner.logout) {
yield put({ type: SET_AUTH, newAuthState: false });
yield call(logout);
forwardTo('/');
}
}
}