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.

RFC: Removing the store.dispatch provided to epics

See original GitHub issue

Hey all, when we originally made redux-observable we thought it would be a good idea to keep the ability to imperatively call store.dispatch inside your epics as basically a rarely used (if ever) escape hatch to just “get things done”. While it would be nice to have it just in case, I’m quite concerned with the number of new people I come across who use it extensively and even exclusively, rather than emitting actions. I even see calls inside map and I feel like it’s our fault for giving people the gun to shoot themselves with. I see this in stackoverflow, gitter, and even youtube tutorials on how to use redux-observable. 😢

Sooo. I’m proposing we remove it entirely from epics. I’m not sure what that means for the function signature of epics but I imagine it would change since the second argument object would only have getState now and that’s just weird. If we generally have consensus to remove dispatch, having it as part of the store enhancer effort since that will provide a cleaner migration/deprecation path for people. If that’s the case, both of these and a few other minor things would probably be part of us finally starting to move towards a 1.0. Starting with 1.0.0-alpha release first, then beta, etc.

Thoughts? I’m definitely willing to hear out people’s arguments for keeping it.

Cc/ @BerkeleyTrue @rgbkrk

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
rgbkrkcommented, Jan 26, 2018

merge and of are your friends here. You can emit the one action along with the other stream of actions

action$
  .filter(
    (action: actions.IApplicationAction) => action.type === actions.SEND_EMAIL
  )
  .flatMap(payload =>
    merge(
      // The initial action of processing it
      of(actions.processingSubmission(true)),

      // The follow on stream
      Observable.from(fetch(endpoint))
        // The resulting action created from it
        .mapTo(someAction)
    )
  );

Apologies to Jay for answering it here instead of SO, just for the sake of having a canonical (?) answer here while an SO post is hopefully created. Note: I matched the style above, this is how I’d really handle it:

action$.pipe(
  ofType(actions.SEND_EMAIL),
  mergeMap(payload =>
    merge(
      // We are processing
      of(actions.processingSubmission(true)),
      Observable.from(fetch(endpoint)).pipe(
        // It worked, tada!
        mapTo(someAction),
        // Oh no it failed!
        catchError(err => actions.processingSubmissionFailed(err))
      )
    )
  )
);

2reactions
MmtBkncommented, Feb 22, 2018

I think It was a good feature… or am I one of those shooters??

https://stackoverflow.com/questions/48931708/whats-the-proper-way-to-dispatch-action-inside-epic

     // show operation failed message
    (action$, store) => action$.ofType(OPERATION_FAILURE).map(() => (error({
        title: 'Operation Failed',
        message: 'Opps! It didn\'t go through.',
        action: {
            label: 'Try Again',
            autoDismiss: 0,
            callback: () => store.dispatch(operationReset())
        }
    }))),
Read more comments on GitHub >

github_iconTop Results From Across the Web

Epics - Redux Observable
REMEMBER: Epics run alongside the normal Redux dispatch channel, after the reducers have already received them. When you map an action to another...
Read more >
New: Helper for clean two way data binding with vuex - RFCs
Problem. Writing clean two way data binding with vuex is a bit tedious and repetitive, and it can lead to a lot of...
Read more >
Channel Access - EPICS
The goal of channel access (CA) is to provide remote access to records and ... This value will allow the client library to...
Read more >
EPICS Documentation - EPICS Controls
It shall be possible to store acquired operational data for the long term and to retrieve it in the original form. EPICS provides...
Read more >
The eduroam Architecture for Network Roaming RFC 7593
This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) in effect on the ...
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