-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
Shape of props depends on number of stores #22
Comments
Agreed, the current behavior is too implicit. I like where you're going with “never flatten” but you can't do the same for the decorator. I guess the decorators could accept a second <Container stores={[boardStore]}
actions={{ addList }}>
{({ boardStore, ...props }) => <Board board={boardStore} {...props} /> }
</Container> @container({
stores: [boardStore],
actions: { addList }
}, ({ boardStore, ...props }) => ({ board: boardStore, ...props }))
class Board { Thoughts? |
Another thing to consider is that ideally the container would filter the props Otherwise it's easy to accidentally pass props from stores you haven't subscribed |
What about defining stores as object or as a function where we can return a state using restructuring? I'll try to submit a proposal tonight. |
Agreed with @fson. @ooflorent this goes against the whole purpose of stores being simple reducing functions (as far as I understood your proposal.) But, I agree we should have access to all data in Redux, maybe with a |
Here's something even more explicit. I think I like it: <Container stores={[boardStore]}
actions={{ addList }}>
{({ actions, stores }) => <Board board={stores.boardStore} {...actions} /> }
</Container> This works great with other possible usage patterns: <Container stores={[boardStore]}
actions={{ addList }}>
{({ actions, stores }) => <Board {...stores} {...actions} />}
</Container> <Container stores={[boardStore]}
actions={{ addList }}>
{({ actions, { boardStore } }) => <Board {...boardStore} {...actions} />}
</Container> or even <Container stores={[boardStore]}
actions={{ addList }}>
{({ actions, stores }) => <Board stores={stores} actions={actions} />}
</Container> It's also good if you don't care about the actions (or the stores): <Container actions={{ addList }}>
{({ actions }) => <Board actions={...actions} />}
</Container> If somebody wants to take shot at it, let me know here :-) I'm busy with thinking about middleware at the moment, but I'm happy to merge the version I described above, with the addition of
(which was a regression in 0.3.0 rewrite) |
It might be that for consistency, we should change <Container stores={{ boardStore }}
actions={{ addList }}>
{({ actions, { boardStore } }) => <Board {...boardStore} {...actions} />}
</Container> Now, <Container stores={{ board: boardStore }}
actions={{ addList }}>
{({ actions, stores }) => <Board {...stores} {...actions} />}
</Container> In the @container({
stores: { board: boardStore },
actions: { addList }
// by default transformProps is ({ stores, actions }) => { ...stores, ...actions }
}); @container({
stores: { boardStore },
actions: { addList }
}, ({ actions, stores }) => ({ board: stores.boardStore, ...actions })); // but can customize |
@gaearon your proposal is what I was thinking about. If no one submit a PR I'll do it tomorrow. |
👍 |
@gaearon I really like that proposal, makes it very clear what is happening. PR coming in a moment. |
This is out in 0.6.0. |
Thanks! |
Changing the names of props based on number of stores subscribed to seems tricky.
Let's say I have a dumb component that takes a prop
board
({ name: 'My Board' }
), which should come fromboardStore
:But because I only subscribed to one store, it gets flattened and the component only receives
name
prop.If I need to add a subscription to another store
userStore
, the props change to:I think it would be simplest, if the data would never be flattened. Then I can always just do:
Another way could be to pass another function or a map of functions to map the state from stores to
props, but I think I actually prefer the former because of its simplicity.
The text was updated successfully, but these errors were encountered: