A
A
Andrey2017-04-25 16:54:18
React
Andrey, 2017-04-25 16:54:18

Where in React / Redux / Saga to compare the received data with the store?

I receive data from the server with Ajax - a list of news.
It is necessary to filter from the list only those news that are not yet available and add them.
Here is the Saga code:

function* getNewsUpdate({payload}) {
    try {
        const response = yield call(getLatestNews,payload.lang);
        yield put({type: "LOADED_NEWS", payload: {lang: payload.lang, loadedNews:  response}});
    } catch (err) {
        console.log(err);
    }
}

Here I have a list of downloaded news, but no storage access.
And the nearest place where I can compare the resulting list with the store is the reducer:
case 'LOADED_NEWS':
            let {lang, loadedNews} = action.payload;
            let newElements = filterNewItems(state[lang], loadedNews);
            return {...state,
                [lang]: [...state[lang], ...newElements]
            };

But there is a feeling that the filterNewItems function in the reducer is not appropriate at all. it's not a place to manipulate data. But how can I compare the received data with the state before the reducer - I'll never know.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
KnightForce, 2017-05-15
@KnightForce

In the reducer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question