kutlugsahin / redux-saga-callback Goto Github PK
View Code? Open in Web Editor NEWredux-saga helper functions to await dispatched actions
License: MIT License
redux-saga helper functions to await dispatched actions
License: MIT License
could you show me how can i use this with redux-toolkits.thanks
Firstly, thanks for this code. It's in TypeScript, which is a big win, and provides a valuable approach on the topic of saga composition.
In the case where I want the dispatched action to actually be processed by the reducers, will that happen?
My issue is that when I yield call(effect, action())
, the action doesn't reach my redux store. In some cases, that's an issue. I could split my actions into saga triggering events and redux reducer actions, but that seems a bit convoluted, error prone, etc. I guess to work around this would require a redux middleware... ๐ค
I'm a little stuck. I recieve the callback to the action creator but unable to send that to the intial call function at Login. Any help would be appreciated
Login
handleOnLogin = async (values, actions) => {
const { email, password } = values;
try {
const response = await this.props.signIn({ email, password });
if (response.authentication) {
this.props.navigation.navigate("Home");
}
};
Actions
export const signIn = ({ email, password }) => {
reduxStore.store.dispatch({
type: Actions.SIGN_IN_REQUEST,
payload: {
email: _.trim(email),
password: _.trim(password)
},
onComplete: ({ error, cancelled, data }) => {
console.log("ACTIONS", { error, cancelled, data });
return data
}
});
};
Sagas
const signIn = function* signIn({ payload }) {
try {
const { email, password } = payload;
const response = yield call(API.signIn, { email, password });
// yield putWait({ type: Actions.SIGN_IN_SUCCESS, payload: response });
return { response, authentication: true };
} catch (error) {
// yield putWait({ type: Actions.SIGN_IN_FAIL, error });
return { error, authentication: false };
}
};
i follow your example to change my code. i still can not get call back in component. Is the redux-saga-callback package is fail?
First of all thanks for this library.
But looks like putWait won't work for
takeLatest(actiontype, withCallback(...
->takeLeading(actiontype, withCallback(...
->take latest example
function* fetchUsers() {
const users = yield fetch('/users');
// put users to store
yield put(putUsers(users));
// returned value will be passed to onComplete function as parameter
// Exceptions will be handled by the withCallback and will also be passed to onComplete
return users;
}
export function*(){
yield all([
takeLatest('FETCH_USERS', withCallback(fetchUsers))
])
}
function* sample() {
yield fork(function* () {
yield putWait(fetchUsers()); // will be completed before users loaded because first handler is cancelled
const users = yield select(getUsers); // here users will be null
});
yield fork(function* () {
yield putWait(fetchUsers());
const users = yield select(getUsers);
});
}
takeLeading example
....
export function*(){
yield all([
takeLeading('FETCH_USERS', withCallback(fetchUsers))
])
}
function* sample() {
yield fork(function* () {
yield putWait(fetchUsers());
const users = yield select(getUsers);
});
yield fork(function* () {
// this putWait never completes because takeLeading ignore second action while first one is processing
yield putWait(fetchUsers());
const users = yield select(getUsers);
});
}
Maybe you have any idea how to get working it in these cases. Thanks in advance!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.