Accessing actions from custom middleware
See original GitHub issueWorking on an example app, I’m wondering how I should best access a specific action? (Like from const action = new dsm(...).actions()
). They could be hard-coded, but that seems like a fragile anti-pattern. I’d think there would be a way of using my original states (initialize
, fetch
, etc) but there doesn’t really seem to be a good way to do this. If actions
was exposed as a map, it could be actions.initialize
or actions.fetch
, for example.
Thoughts?
Code:
const dsm = require('redux-dsm');
const fetchingStates = [
['initialize', 'idle',
['fetch', 'fetching',
['cancel', 'idle'],
['report error', 'error',
['handle error', 'idle']
],
['report success', 'success',
['handle success', 'idle']
]
]
]
];
const myDsm = dsm({
component: 'myComponent',
description: 'fetch foo',
actionStates: fetchingStates
});
const actions = myDsm.actions;
const customMiddleware = store => next => action => {
Assuming I want to handle a specific action, how do I access it?
}```
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Write custom ASP.NET Core middleware - Microsoft Learn
NET Core provides a rich set of built-in middleware components, but in some scenarios you might want to write a custom middleware.
Read more >Call controller and action from custom middleware
MvcRouteHandler , set controller and action based on custom logic. context.RouteData.Values["area"] = "MyArea"; context.RouteData.
Read more >Async actions in bare Redux with Thunk or custom middleware
Learn how to manage asynchronous actions in React apps with Redux Toolkit, or a bare Redux implementation with custom middleware.
Read more >Redux Course Lesson #7: a custom middleware for ... - YouTube
Redux Course Lesson #7: a custom middleware for async actions · Key moments. View all · Key moments · Description · Key moments....
Read more >How to access action metadata and custom attributes of an ...
Each action is an Endpoint and you can get all custom attributes of the action from Endpoint metadata. Remember you need to place...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Merged. Will look at releasing the change with a major version bump soon.
I would like to propose an alternative
What user provides is this array of states, actions and transitions:
and I like how the
actionCreators
maps state transitions to methods.If I understand correctly what you are proposing David is to have the same structure in
actions
so callingactions.handleSuccess
would return string value.How about combining those two and instead of having both
actionCreators
andactions
do something like this:On the other hand, I don’t like adding another level of nesting and it seems reasonable to just import
{ handleSuccess, handleError} from './myActionCreators'
and then simply call it without accessing nestedcreator
. With this in mind I’m leaning toward David’s idea which doesn’t include additional nesting but I’m posting above as the food for thought.