Метод Put Реду-Сага не запускает соответствующий Редуктор - PullRequest
0 голосов
/ 23 апреля 2020

Это моя сага (индекс и специфика c сага): Индекс саги:


    import { all } from 'redux-saga/effects';

    import search from './search';

    export default function* rootSaga() {
        yield all([search]);
    }


Специфика c Сага:


    import { put, call, takeLatest } from 'redux-saga/effects';
    import {
        SEARCH_MOVIE_START,
        SEARCH_MOVIE_COMPLETE,
        SEARCH_MOVIE_ERROR,
    } from '../../consts/actionTypes';

    import { apiCall } from '../api';

    export function* searchMovie({ playload }) {
        try {
            console.log('Accion inical');
            const results = yield call(
                apiCall,
                `&s=${playload.movieName}`,
                null,
                null,
                'GET'
            );
            yield put({ type: SEARCH_MOVIE_COMPLETE, results });
        } catch (error) {
            yield put({ type: SEARCH_MOVIE_ERROR, error });
        }
    }

    export default function* search() {
        yield takeLatest(SEARCH_MOVIE_START, searchMovie);
    }

Как видите, В этой саге есть метод console.log () и метод put (), но ни console.log (), ни put () не работают, я имею в виду, что в консоли браузера нет сообщений. Также я использую Redux DevTools и в разделе действий отображаются только SERACH_MOVIE_START, но не отображаются SEARCH_MOVIE_COMPLETE или SEARCH_MOVIE_ERROR (в случае сбоя моего вызова в моем API)

введите описание изображения здесь

Мой редуктор (индекс и специфика c редуктор): Мой индекс:


    import { combineReducers } from 'redux';
    import search from './search';

    const rootReducer = combineReducers({
        search,
    });

    export default rootReducer;

Мой спецификатор c редуктор


    import {
        SEARCH_MOVIE_COMPLETE,
        SEARCH_MOVIE_ERROR,
        SEARCH_MOVIE_START,
    } from '../../consts/actionTypes';

    const initialState = {};

    export default function (state = initialState, action) {
        switch (action.type) {
            case SEARCH_MOVIE_START:
                return { ...state };
            case SEARCH_MOVIE_ERROR:
                console.log(action);
                return { ...state };
            case SEARCH_MOVIE_COMPLETE:
                console.log(action);
                return { si: 'no lo creo', ...state };
            default:
                return { ...state };
        }
    }

и хранилище:


    import { createStore, applyMiddleware } from 'redux';
    import createSagaMiddleware from 'redux-saga';
    import { composeWithDevTools } from 'redux-devtools-extension';

    import rootReducer from '../reducers';
    import rootSaga from '../sagas';

    const configureStore = () => {
        const sagaMiddleware = createSagaMiddleware();
        return {
            ...createStore(
                rootReducer,
                composeWithDevTools(applyMiddleware(sagaMiddleware))
            ),
            runSaga: sagaMiddleware.run(rootSaga),
        };
    };

    export default configureStore;

...