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

Reducers proposal: changes & relations #26

Open
yoursdearboy opened this issue Apr 11, 2016 · 2 comments
Open

Reducers proposal: changes & relations #26

yoursdearboy opened this issue Apr 11, 2016 · 2 comments

Comments

@yoursdearboy
Copy link

Hi. In my app I have two reducers that I always use with redux-crud:

  • RECORD_CHANGE - to change some record (on client, without update to server)
  • A bit complex one to update relations. An example: posts has comments
{
  posts: [{id: 1, title: 'Post', comments: [1,2]}],
  comments: [{id: 1, text: 'Comment #1'}, {id: 2, text: 'Comment #2'}]
}

Posts' reducer listens for COMMENTS_CREATE_START, COMMENTS_CREATE_SUCCESS, COMMENTS_DELETE_SUCCESS and updates comments ids in posts.

They are tightly related to crud operations to be in this package. What do you think? I can make a PR with tests.

Also, thx for answering my previous question (sorry, I hadn't noticed the old one issue on the same topic).

@sporto
Copy link
Contributor

sporto commented Apr 14, 2016

Hi
Could you be a bit more specific on what you are proposing? I see how you are using the actions but I am not following what this PR would do.

Also, we don't store comments inside the post, like your example. We do it the other way around:

comments: [{id: 1, post_id: 1, ...}]

So I wouldn't like to be prescriptive about this.

@yoursdearboy
Copy link
Author

I propose to extend the library with a reducer that will update such ids arrays. Because it should know where to look for them, also this change involves modifying reducersFor to accept an description object. Here is a simple gist to demonstrate what I mean (without modifying redux-crud itself).

There's no such problem if handle relations like you are doing. But, how did you got post_id in the comment resource? Does your API return it with post_id (a bit strange for REST) or is it a part of normalization? After all, it looks like a relational database on top of redux store. I'm new to the modern web and wonder if it's a good idea?

Anyway, I've just wanted to know what do you think about it. I think that have such reducer out of the box is nice. If this use-case doesn't fit redux-crud and somebody will be interested, I can publish it as a separate package.

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