Skip to content
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

How to handle ADD_TODO and DELETE_TODO? #9

Open
cristian-sima opened this issue Apr 10, 2017 · 1 comment
Open

How to handle ADD_TODO and DELETE_TODO? #9

cristian-sima opened this issue Apr 10, 2017 · 1 comment

Comments

@cristian-sima
Copy link

Hi.

I think this package is great. However, in order to use it I do not understand how to integrate 2 features: ADD and DELETE.

The naive approach would be to reset the entire pagitated todos when I am adding a new one. (and also the cached requests). I feel this is a bad approach as I already know that the item that I am adding is the last one and I can add it inside the paginated reducer, however it does not allow me to increment any sort of counter. I have just the page counter, which I can not increment.

A better solution is to have a counter which tells me which was the last ID that I have fetched. In this sense, I can increment or decrement it.

Of course it is a discussion regarding the sorting type. In that matter, we can provide different reducers for different types of sorting.

Any idea on this subject? If so, can you provide a very small example of integrating ADD and DELETE with this package?

@juandjara
Copy link

You can build logic for adding and deleting items in the reducer you use for composing the itemsReducer provided by redux-pagination

I'm trying to implement the logic like this:

const panelsReducer = (state = {}, action = {}) => {
  const { type, payload } = action
  switch(type) {
    case PANEL_CREATE:
    case PANEL_EDIT:
      return {
        ...state,
        [payload.id]: payload
      }
    case PANEL_DELETE:
      const copy = Object.assign({}, state)
      delete copy[payload.id]
      return copy
    default:
      return panelPaginator.itemsReducer(state, action)
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants