question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Accessing actions from custom middleware

See original GitHub issue

Working 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:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ericelliottcommented, Apr 28, 2017

Merged. Will look at releasing the change with a major version bump soon.

1reaction
bognixcommented, Apr 19, 2017

I would like to propose an alternative

What user provides is this array of states, actions and transitions:

  ['initialize', 'idle',
    ['fetch', 'fetching',
      ['cancel', 'idle'],
      ['report error', 'error',
        ['handle error', 'idle']
      ],
      ['report success', 'success',
        ['handle success', 'idle']
      ]
    ]
  ]
];

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 calling actions.handleSuccess would return string value.

How about combining those two and instead of having both actionCreators and actions do something like this:

    handleSuccess: {
        creator: () => {},
        name: "NAME"
    },
    ...
}

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 nested creator. 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found