redux-async-connect icon indicating copy to clipboard operation
redux-async-connect copied to clipboard

Way to trigger load manually

Open krzysztofpniak opened this issue 9 years ago • 9 comments

What about scenario with the refresh button on the page that enables user to grab fresh data without clicking around navigation.

I have small idea how this can be achived. You can add reload function on the same level we have loading and loaded properties. That function should just be the proxy to call again the promise funcion provided in @asyncConnect.

krzysztofpniak avatar Feb 09 '16 16:02 krzysztofpniak

Hi @krzysztofpniak Thanks for suggestion, it's interesting idea, but i don't think putting the function to the store is a good idea. Store should be serialisable object... you can achieve this manually reloading the data and dispatching loadSuccess action (from redux-async-connect) ...

sars avatar Feb 12 '16 00:02 sars

Hello @sars my idea wasn't about putting it to state, but to put it into object that is connected to react component only.

krzysztofpniak avatar Feb 12 '16 04:02 krzysztofpniak

Hi, @krzysztofpniak loaded and loading properties set by AsyncConnect are stored in store and connected to component.

Given that func you want should not be stored in store, AsyncConnect has nothing to do with it, as it connects store data only.

So if you want to extend connected data in your component, you should do it yourself. As @sars mentioned, you can import and dispatch loadSuccess action to reload AsyncConect data in store.

quarryman avatar Feb 13 '16 18:02 quarryman

Hello @quarryman , thanks for the explaination. I'm relatively new to Redux, so I might be wrong, but from my perspective there is nothing wrong with creating functions from the store and connect them to component. On the other hand I can say that asyncConnect should not contain its own reducer which adds loaded and loading, it should just dispatch load function. I hope you do not get me wrong. I'm just wondering why putting functions are bad, the state is not modified, store is serializable and components are stateless.

krzysztofpniak avatar Feb 13 '16 19:02 krzysztofpniak

@krzysztofpniak, basically js function is serializable, however it still might reference current scope variables and if you put func into state and try to use it later how can you guarantee func will be invoked within the same scope? Still it's controversial Basically Redux tells us that state must be a plain object. Any functions that aim to modify state should be implemented as reducer. That's the idea of react.

quarryman avatar Feb 17 '16 12:02 quarryman

@quarryman, which part of my answer was telling about putting a function to a state or about modifying a state from that function?

krzysztofpniak avatar Feb 17 '16 12:02 krzysztofpniak

Can you plz clarify your statement ?

but to put it into object that is connected to react component only.

What is connected can be state property or action creator. Did you mean function that is action creator?

quarryman avatar Feb 17 '16 14:02 quarryman

@krzysztofpniak @quarryman @sars I'm wondering about a similar approach here: https://github.com/Rezonans/redux-async-connect/issues/41

If I move my logic from an action dispatcher and a reducer to use solely the asyncConnect decorator, I have successfully gotten rid of two unnecesssary redundancies. However, if i cannot reload the data manually, then i still would need to invoke a dispatch of a new redux action, wait for the success action, then set data again. That seems redundant to me, given that if asyncConnect is handling the loading on the first load/route change, it should be able to handle it on manual invocation.

What about exposing an API call that would simply dispatch a LOAD again? The same one that is in the asyncConnect decorator already, we wouldn't need to serialize anything at that point. Just allow for the LOAD to be dispatched manually, and handle the success/failure calls the same way they're being handled now.

kjanoudi avatar Feb 18 '16 21:02 kjanoudi

Hi @kjanoudi , @krzysztofpniak , please, see my comment in #41

sars avatar Feb 23 '16 21:02 sars