-
Notifications
You must be signed in to change notification settings - Fork 179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any example how to integrate redux-saga with ng-redux? #82
Comments
I think you'll find you need to run the export function ConfigRedux($ngReduxProvider) {
$ngReduxProvider.createStoreWith(rootReducer, [sagaMiddleware]);
}
export function RunRedux() {
sagaMiddleware.run(helloSaga);
} angular.module('myModule', []).config(ConfigRedux).run(RunRedux); |
the solution doesnt work for me. I am applying your solution: import sagaMiddleware from 'redux-saga';
...
angular.module('myModule', []).config(ConfigRedux).run(RunRedux);
function ConfigRedux($ngReduxProvider) {
$ngReduxProvider.createStoreWith(rootReducer, [sagaMiddleware]);
}
function RunRedux() {
sagaMiddleware.run(helloSaga);
} sagaMiddleware.run(helloSaga) is throwing the following exception: Uncaught TypeError: _reduxSaga2.default.run is not a function According to the saga tutorial, you need to call run in the result of calling createSagaMiddleware // ...
import { createStore, applyMiddleware } from 'redux'
import createSagaMiddleware from 'redux-saga'
// ...
import { helloSaga } from './sagas'
const sagaMiddleware = createSagaMiddleware()
const store = createStore(
reducer,
applyMiddleware(sagaMiddleware)
)
sagaMiddleware.run(helloSaga) Any ideas? |
It looks like you're assigning the default import from redux-saga to sagaMiddleware, but it actually returns a factory, so you need to initialise a sagaMiddleware, pass that into import createSagaMiddleware from 'redux-saga'
import rootReducer from './reducers'
import { helloSaga } from './sagas'
const sagaMiddleware = createSagaMiddleware()
angular.module('myModule', []).config(ConfigRedux).run(RunRedux);
function ConfigRedux($ngReduxProvider) {
$ngReduxProvider.createStoreWith(rootReducer, [sagaMiddleware]);
}
function RunRedux() {
sagaMiddleware.run(helloSaga);
} |
I tried that as well but it doesn't work. I get the following error:
@jeremygrant have you tried yourself in a project to make it work? I am starting to think that ngRedux is incompatible with this middleware... Btw, many thanks in advance |
@jhuesos yep I have it working. This is a stripped back version of what I have. import angular from 'angular'
import ngRedux from 'ng-redux'
import createSagaMiddleware from 'redux-saga'
import rootSaga from './sagas'
import rootReducer from './reducers'
const sagaMiddleware = createSagaMiddleware()
angular.
module('app', [ngRedux]).
config(['$ngReduxProvider', ($ngReduxProvider) => {
$ngReduxProvider.createStoreWith(rootReducer, [sagaMiddleware], [], {})
}]).
run(() => { sagaMiddleware.run(rootSaga) }) Based on your error the only thing I can think of that could be causing it in your version and not mine is that I'm injecting $ngRedux elsewhere, so it may just be luck that $ngReduxProvider.$get is getting called before the sagaMiddleware.run is called. If that's the case I'd imagine it would work for you as is if you change function RunRedux() {
sagaMiddleware.run(helloSaga);
} to function RunRedux($ngRedux) {
sagaMiddleware.run(helloSaga);
} If that doesn't help, it may be a version issue? I'm using these versions:
|
Yes, apparently I need to inject $ngRedux in the run function to make it work.... It is strange, isn't it? I am a newbie with redux/ngredux, but do you think this is a bug on ngredux or redux-saga? |
Most likely not a bug (it's a feature 😉 ). You're doing: function ConfigRedux($ngReduxProvider) {
$ngReduxProvider.createStoreWith(rootReducer, [sagaMiddleware]);
}
function RunRedux() {
sagaMiddleware.run(helloSaga);
} But So here, By doing something like: myModule.run([$ngRedux, ngRedux => sagaMiddleware.run(helloSaga)) You're forcing angular to run |
Assuming the issue is resolved. |
@wbuchwalter great work on this package u should consider adding a section of how to configure redux-saga in angular as redux-saga is used by a lot of people |
@jeremygrant @nahidupa how can I inject $resource to a saga? or r u using |
@sibelius I use fetch, which works nicely with the sagas: |
i'm tried to integrate with redux-saga middleware.
But getting following error
"Before running a Saga, you must mount the Saga middleware on the Store using applyMiddleware(…)"
My code is look like
export function ConfigRedux($ngReduxProvider) {
$ngReduxProvider.createStoreWith(rootReducer, [sagaMiddleware]);
sagaMiddleware.run(helloSaga);
}
My understanding is createStoreWith do applyMiddleware internally. What i'm missing here?
The text was updated successfully, but these errors were encountered: