Comments (4)
Examples
in redux-thunk:
https://github.com/gaearon/redux-thunk#injecting-a-custom-argument
in redux-observable:
https://redux-observable.js.org/docs/recipes/InjectingDependenciesIntoEpics.html
from redux-most.
@jshthornton We should think about this also when considering the withStore
and withState$
higher order functions we talked about.
from redux-most.
@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?
from redux-most.
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?
from redux-most.
Related Issues (20)
- Setup gitter community HOT 4
- Document 'select' behavior HOT 6
- Rewrite createEpicMiddleware without Subjects to simplify and shrink build (removes replaceEpic) HOT 7
- Passing non-functions to combineEpics() results in unhandled promise rejection. HOT 4
- Add tests for TypeScript definitions
- deleted
- Change combineEpics to accept an array of epics HOT 1
- delete
- Experiment with Proxies as a replacement for Subjects
- Consider changing API to use higher order functions to inject the state stream or store HOT 4
- redux-thunk instead of actions HOT 5
- Async subject causes incorrect behaviour of an input caret HOT 5
- TypeScript error with Redux 4 HOT 1
- "Dispatching while constructing middleware" error with Redux ^4.0.0 HOT 3
- Updating to @most/core HOT 7
- Does not work with Typescript 3.4 HOT 1
- Release new version that works with @most/core? HOT 1
- Append an epic to an in-progress epic HOT 1
- Not working without redux-thunk
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redux-most.