-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Connecting to both Redux and non-Redux store #713
Comments
Effect creator is a function returning a description-object, look at this. Also the created effects are later interpreted here. So for allowing custom effects we would need to expose hooks to those internals and document how to work with it, might make sense for other use cases, but for yours it seems like an overkill. Im wondering - isnt just importing an external module containing a reference to your Also - the title of the issue implied for me that this could be used. |
Yep, I know, and I agree that it's probably an overkill for this problem, however I still think that custom effects is a feature that should be added one day. It would be useful for many things. Currently you can code it as a composition of built-in effects, e.g. function safeCall(...args) {
return call(function* safeWrapper() {
try {
return yield call(...args);
} catch (e) {
return null;
}
});
} But it won't look nice in the monitor and there's no way for it to access saga runtime stuff.
I'm trying to refactor some code that uses this approach to something that won't involve global variables. These connections are not singletons and are created and destroyed often. React Context allows components to access objects owned by their far ancestor, while avoiding globals and passing objects down the whole hierarchy via props. This makes it possible to attach a Redux store once near the root component and then use it in any other descendant. I think this kind of inversion of control would be really useful in sagas, because they too often form a deep hierarchy.
I want to still be able to |
Out of curiosity - what saga runtime stuff you would like to have access to?
But would abstract your connections and you wouldnt need to care about it in your sagas |
Maybe the options passed to middleware, or arguments of root saga.
I would still need to care about it, by |
Well, I guess allowing custom effects wouldnt be even that much of a problem, only if they are self contained and do not need access to the WDYT @yelouafi ? |
After some more thinking I agree that custom effects are actually useful only for Monitor. But I guess there are simpler ways of making them look nice, while still having them composed of built-in effects. Introducing function* parent() {
yield setContext({foo: 'bar'});
yield fork(child);
}
function* child() {
const foo = yield getContext('foo'); // 'bar'
} |
does React's |
When parent component is updated, it can return new We could make it more minimalistic, allowing only const sagaMiddleware = sagaMiddlewareFactory({context: {...}});
// or
sagaMiddleware.setContext({...}); |
Seems like the concept dynamic scoping. I think it could be helpful for things like dep. injection. This could be implemented using prototype chaining of JS objects. We can pass an additional arg to |
…amic scoping between parent/child tasks (resolves #713)
Closing in favor of #735. |
…amic scoping between parent/child tasks (resolves #713)
…amic scoping between parent/child tasks (resolves #713)
…amic scoping between parent/child tasks (resolves #713)
I have some stuff that I can't put into Redux store because it is not serializable and not immutable. More precisely, a Connection object that is created and managed by a third-party lib. To avoid passing connection via Redux action, I use Channels. It works quite well, despite the need to pass channels to every saga that needs the connection.
However, a lot of generators aren't started on application startup, so they don't have a chance to catch the connection from channel. To workaround this, I have to pass connection along with channel to lots of generators which is not convenient at all.
I have one idea how to solve this. It's a common practice to assign third-party clients to Redux store like this:
Then you're able to use the client in React components.
Saga runtime is connected to the store, although only to
getState
anddispatch
. But if we connect runtime to the whole store, we could introduce custom effect creators like this:And then use it in any generator without the need to pass connection as argument:
Maybe there's a more elegant way, like introducing something similar to React Context.
The text was updated successfully, but these errors were encountered: