developit / developit/unistore

[feat] Namespacing actions

Open
#170 2 comments 0 reactions 0 assignees View on GitHub
discussion enhancement
Dominant language
JavaScript
Stars
2.8k
Forks
134
PR merge metrics
No merged PRs in 30d

Description

Hello,

When using actions I see two problems.

1. If there are alot of actions, they kind of pollute the prop root and cause prop hell.
2. There's no good way of using two different action objects.
```JSX
import { actions as itemActions } from 'store/item/actions';
import { actions as authActions } from 'store/auth/actions';
```
Sure, we could combine those two and merge into one object by borrowing the excellent `combineActions` from `redux-zero`
https://github.com/redux-zero/redux-zero/blob/3d0b032c0f3c94757e307673d46e9c52327f3b75/src/utils/combineActions.ts

```JSX
...
const actions = combineActions(itemActions, authActions);
const Connected = connect('item,auth', actions)(PleaseConnectMe);
...
```
But problem this time is if both `itemActions` and `authActions` have a `reset` action they will collide.

So to solve these two, would it be an idea to implement some kind of prop namespacing? Without discussing the implementation, wouldn't it be an idea to have the itemActions in the example accessible via `this.props.itemActions.actionName` instead of `this.props.actionName`.

Would there be any cons with above aproach?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.