JavaScript Extension of essence in redux

I don't know what your references to models mean; my assumption is that you're talking about the models on the backend, but that doesn't really affect us here so I'm going to ignore them.

Using actions for fetching and formatting data in Redux

Let's start with this statement:

It works fine for pages with lists, but the article models differ for the index route and get the route

This doesn't actually matter! It is okay that the data is different between the routes (even if it isn't ideal).

I don't know where you are handling your API requests currently, but I recommend putting them into Redux Actions. Using the middleware Redux Thunk we can have functions in our action creators. Part of an action's job is to prepare data for the reducer. This means that we can use functions in actions to format the data so it always the same when it hits the reducer. This means we don't need to write many similar reducers to handle the same entity type, keeping things DRY and making it much, much easier to maintain.

In this scenario I would have three actions:

getAllArticles()

getArticlesById(id)

putArticles(articles)

The two get article actions would be responsible for making the request, formatting the data. They then take this data and pass it to putArticles which actually dispatches the action the reducer is listening for.

Your methods would look something like this:

const getAllArticles = () => {
   return (dispatch, getState) => {
      fetch(yourRoute).then((json) => {
        const formattedData = json // format/normalize your data here
        dispatch(putArticles(formattedData))
      }
   }
}

const getArticleById = (id) => {
   return (dispatch, getState) => {
      fetch(yourRoute + id).then((json) => {
        const formattedData = json // format/normalize your data here
        dispatch(putArticles(formattedData))
      }
   }
}

const putArticles = (articles) => {
   return {
      type: 'PUT_ARTICLES',
      payload: {articles}
   }
}

Normalizing data

The next step I would look at is normalizing your data. You've actually done a pretty good job of splitting entities out and keeping paginated info separate from the actual entities list.

I would break your store down by entity type.

state = {
   articles: {
      entities: { /* each article by ID */},
      result: [/* array of ID, primary used for looping */],
      pagination: { /* various pagination methods */ }
   },
  ...
}

Normalizing the data prevents you form having nested resource lists (articles > users > comments, as an example). You've pretty much done this, formalizing it with a library likeNormalizr will allow you to standardize the way you handle data.

I would move pagination into the individual entity (user, article). This keeps things neatly separated by their type and prevents having this massive list of unrelated data.

Going deeply into normalization as a whole is outside of the scope of a SO question, but take a look at these two links:

Normalizing Redux State Shape

Updating Normalized Data

Answer:1

There is a string value in a p class like <p id="demo">10 hours : 25 minutes : 20 seconds</p>. Here I want to split that value like 10:25:20. This is my javascript function. function ...

There is a string value in a p class like <p id="demo">10 hours : 25 minutes : 20 seconds</p>. Here I want to split that value like 10:25:20. This is my javascript function. function ...

  1. getting html value in jquery
  2. html getting value from input box
  3. html getting value from select
  4. html getting value from input
  5. getting html textbox value in javascript
  6. getting html textbox value in c#
  7. getting button value html
  8. getting default value html

So I am using readline-sync to perform basic calculations. Multiplying and dividing work fine, but when I add both numbers it just concatenates them and when I subtract it returns NaN. Any idea what ...

So I am using readline-sync to perform basic calculations. Multiplying and dividing work fine, but when I add both numbers it just concatenates them and when I subtract it returns NaN. Any idea what ...

  1. addition subtraction working model
  2. addition subtraction working wall
  3. addition and subtraction worksheet
  4. addition and subtraction working wall ks2
  5. addition and subtraction working wall year 3
  6. addition and subtraction working wall year 2
  7. addition and subtraction work mat
  8. addition and subtraction working wall year 1
  9. addition and subtraction working wall year 4
  10. addition and subtraction maths working wall

The javascript Date object parse method is "optimistic", that is, it fills in information that is missing with the earliest possible date. e.g. new Date('January 2016'); // = Jan 01 2016 new Date('...

The javascript Date object parse method is "optimistic", that is, it fills in information that is missing with the earliest possible date. e.g. new Date('January 2016'); // = Jan 01 2016 new Date('...

I have 2 div lines, each of them has 4 tabs. If I open one tab in one of the divs, I want the other div tabs to be closed. How can I do that? This is my code (see it live also on codepen): $(...

I have 2 div lines, each of them has 4 tabs. If I open one tab in one of the divs, I want the other div tabs to be closed. How can I do that? This is my code (see it live also on codepen): $(...

  1. instagram
  2. italy
  3. indeed
  4. ikea
  5. iphone 11
  6. instacart
  7. icloud
  8. italy news
  9. i still believe
  10. imdb
  11. impeachment
  12. ihop
  13. internet speed test
  14. iready
  15. iphone 11 pro max
  16. itunes
  17. infinite campus
  18. instant pot