Skip to content

Simplify actions and selectors.#11

Merged
10xjs merged 1 commit intonextfrom
refactor-actions
Dec 23, 2016
Merged

Simplify actions and selectors.#11
10xjs merged 1 commit intonextfrom
refactor-actions

Conversation

@10xjs
Copy link
Copy Markdown
Contributor

@10xjs 10xjs commented Dec 23, 2016

Remove the prop merging magic from the selectors. The original intention was to allow multiple instances of a component with a given id to exist, but to have them collapsed down and merged in the selector. This would have been useful for a component that was the product of props from a route component and a dispatched component. However the complexity this added far outweighed the benefit, and the behavior was not intuitive.

The new version of addComponent no longer has the option for a custom id, and will not result in props merging with existing components.

A new setComponent action is used when the id must be explicitly specified. If an existing component with the given id exists, it is replaced rather than merged on to.

What does remain of the component merging logic is a new updateComponent action that can be used to update the props of an existing component. Props dispatched in the updateComponent are merged into the existing props of the component with the matching id. An update function is also now included alongside the remove function on each component returned through the connector. This offers an interface for updating the state of the component (where update is used like react setState).

Copy link
Copy Markdown
Contributor

@izaakschroeder izaakschroeder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💎 💎 💎

Remove the prop merging magic from the selectors. The original intention was to allow multiple instances of a component with a given id to exist, but to have them collapsed down and merged in the selector. This would have been useful for a component that was the product of props from a route component _and_ a dispatched component. However the complexity this added far outweighed the benefit, and the behavior was not intuitive.

The new version of `addComponent` no longer has the option for a custom id, and will not result in props merging with existing components.

A new `setComponent` action is used when the id must be explicitly specified. If an existing component with the given id exists, it is replaced rather than merged on to.

What does remain of the component merging logic is a new `updateComponent` action that can be used to update the props of an existing component. Props dispatched in the `updateComponent` _are_ merged into the existing props of the component with the matching id. An `update` function is also now included alongside the `remove` function on each component returned through the connector. This offers an interface for updating the "state" of the component where `update` is used like react `setState`.
@10xjs 10xjs merged commit 2c8c4f3 into next Dec 23, 2016
@10xjs 10xjs deleted the refactor-actions branch December 23, 2016 04:14
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

Successfully merging this pull request may close these issues.

2 participants