Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to inject a custom argument into Epics #19

Open
joshburgess opened this issue May 25, 2017 · 4 comments
Open

Add the ability to inject a custom argument into Epics #19

joshburgess opened this issue May 25, 2017 · 4 comments

Comments

@joshburgess
Copy link
Owner

Possible Feature: Add the ability to inject a custom argument into Epics

Consider adding the ability to inject a custom argument into Epics to give access to an API utility or similar dependency, like currently possible with redux-thunk and redux-observable.

We will need to consider how we handle #4 when implementing this.

@joshburgess
Copy link
Owner Author

@joshburgess
Copy link
Owner Author

@jshthornton We should think about this also when considering the withStore and withState$ higher order functions we talked about.

@joshburgess joshburgess changed the title Possible Feature: Add the ability to inject a custom argument into Epics Add the ability to inject a custom argument into Epics May 25, 2017
@mcky
Copy link

mcky commented Oct 5, 2017

@joshburgess Wow, I was just putting together an example to go with a proposal to add this, and I see It's already here!

Looking at the implementation of thunks and redux-observables, this seems fairly easy to add, would you be able to elaborate as to why it's a breaking change?

@joshburgess
Copy link
Owner Author

joshburgess commented Oct 12, 2017

Hi, @mcky

I marked it as a breaking change, because it directly affects the Epic API, and we've been talking about possibly rearranging the order of arguments.

Right now, as of the the last major update, there are two ways to use redux-most. See this section taken from the docs:

redux-most offers 2 separate APIs: a redux-observable-like API, where Epics get passed an action stream & a store middleware object containing dispatch & getState methods, and a stricter, more declarative API, where Epics get passed an action stream & a state stream.

...

Initially, redux-most offered the same API as redux-observable, where Epics received an action stream & a store middleware object containing dispatch & getState methods. However, it now offers both that API and another stricter, more declarative API which eliminates the use of dispatch & getState. The reason for this is that I rarely found myself using the imperative dispatch method. It's not really needed, because you can use switch, merge, mergeArray, etc. to send multiple actions through your outgoing stream. This is nice, because it allows you to stay locked into the declarative programming style the entire time.

However, using getState was still required in epics that needed access to the current state. I wanted a nice, convenient way to access the current state, just like I had for dispatching actions. So, I created an alternate API where Epics receive a stream of state changes rather than the { dispatch, getState } object. This state stream, combined with the new withState utility function, let's you use streams for both dispatching actions & accessing the current state, allowing you to stay focused & in the zone (the reactive programming mindset).

So, we have both of those, and, I'm still considering reversing the argument order on each of them, or evolving the API so that there is only ever one type of Epic and you can modify which extra arguments (other than the action$) you need through higher order functions.

But I haven't narrowed down what the right course of action is yet, so I held off on adding this injecting dependencies feature, since I'm not sure the best way to make it fit in. It is, indeed, a pretty trivial thing to implement, but I'm still unsure about it in the context of changing argument orders, maybe using HOFs, etc....

See #4 for more info on reversing the argument order & HOFs ideas.

Any ideas?

alex2 added a commit to alex2/redux-most that referenced this issue Feb 9, 2018
Raised in issue joshburgess#19 but dismissed in favour of a more elegant HOF
approach, after four months with no project activity, I've gone for
the zero-impact pragmatic solution
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants