feathersjs-ecosystem / feathers-redux

Integrate Feathers with your Redux store
MIT License
114 stars 23 forks source link

Action Type Namespace #20

Closed Sicria closed 7 years ago

Sicria commented 7 years ago

Currently all of the action types are named SERVICE_NAME + ACTION, it would be great if you can specify a namespace to adhere to Ducks.

Or even better would it be possible to pass a function to create the action type, like a formatter.

Example:

(name, action) => `app-namespace/${name}/${action}`;
eddyystop commented 7 years ago

Why would one instance of Redux be used for multiple user apps?

Sicria commented 7 years ago

You could specify whatever you wanted for the action type, so when creating the action types you'd call actionTypeFormatter(name, action) and get the action type that will be used.

Then the user could specify the function in the options on init if they wanted to use custom action types.

const services = reduxifyServices(feathersClient, ['users', 'messages'], {
  actionTypeFormatter: (name, action) => `namespace/${name}/${action}`,
});

https://github.com/erikras/ducks-modular-redux

I have a middleware which logs all of the actions in GA so I can tell the frequency of each action. It's just a basic string match on the namespace so I don't log anything that isn't needed.

This might be a special use-case as I'm not sure if many people do this.

eddyystop commented 7 years ago

I will leave namespacing aside until there is more of an interest in it.

Fell free to reopen this issue.

amaury1093 commented 7 years ago

I actually agree with @Sicria.

What if, unlikely as it may seem, that my own app has an action named SERVICES_MESSAGES_FIND, whose reducer is doing something radically different than what feathers-redux does. There might be confusion when feathers-redux dispatches its action.

I wouldn't go as far as adding a formatter (too overkill), but renaming all actions to something like feathersjs/services/MESSAGES_FIND, feathersjs/services/MESSAGES_FIND_PENDING etc would be an idea to prevent confusion. Plus it's following the Ducks naming convention.

Really, it's just changing this line.

eddyystop commented 7 years ago

It looks like this repo is reaching some level of maturity and the needs are changing.

Perhaps either of you can submit a PR as I'm tied up. The optional namespace can be passed in the option. Please take this pending PR into account https://github.com/feathersjs/feathers-redux/pull/29 .