Closed eliperelman closed 8 years ago
Just tried that in redux-elm-skeleton
and it seems to work just fine:
import { Updater } from 'redux-elm';
import { call, take, fork } from 'redux-saga/effects';
const initialModel = {
greeted: false
};
function* signIn() {
while (true) {
yield take('SayHi');
yield call(() => console.log('take some action...'));
}
}
function* listen() {
yield [
fork(signIn)
];
}
export default new Updater({}, listen)
// .case('SayHi', model => ({ ...model, greeted :true }))
.toReducer();
Could be my boilerplate then, I'll post it.
Boilerplate:
So, I'm doing a bit of work to automate the connection of routes and reducers, so I may have missed something that is causing the error.
OK, doing some more digging it appears that I get a console.log('take some action...')
once for every reducer that uses a saga. For example, let's say I have the following reducers set up at app init:
import reducers from './reducers';
const rootReducer = combineReducers(reducers);
console.log(reducers);
/*
{
app: function() {...},
home: function() {...},
login: function() {...},
routing: function() {...},
somePage: function() {...}
}
*/
Let's say app
, login
, and somePage
are using a reducer with a saga:
export new Updater(init, saga).toReducer();
When the take(SIGN_IN)
occurs, I will get 3 console.log
s. If I go into the login
reducer and remove the saga:
export new Updater(init).toReducer();
Then I only get 2 console.log
s.
I'll try and get this into a reduced repo to debug on.
OK, I have a mostly reduced repo at: https://github.com/eliperelman/redux-elm-37
@eliperelman So the issue is that your Updater hierarchy does not form tree hierarchy and therefore the Sagas as re-instantiated. I am currently working on redux-elm
next version which will warn user to console.
Anyway the idea is that your App/updater
should handle all the actions and proxy them to corresponding pages. Therefore you wouldn't use combineReducers
but do the composition manually in App/updater
. Please have a look at our boilerplate because we solved the routing exactly that way (routing definition)
Perfect, thanks so much for the help! I've incorporated your implementation of the boilerplate with my own dynamic page and routing connect, and it seems to work OK. Thanks again!
Trying to pinpoint the issue, but it seems that every time I try to use
takeEvery
with a simplecall
, the action is executed multiple times, in my case, it seems that theconsole.log
is run 4 times. My reduced case:Running this in a loop instead seems to have the same issue:
In my view I have a button that is bound to a signIn function via:
Adding a console.log to this method only logs a single time, so the event/dispatch isn't happening multiple times:
Reducer, for clarity:
I'm using a bit of changes to the boilerplate, so I'll post that as well shortly.