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

How to invoke on client side?

Open kjanoudi opened this issue 9 years ago • 6 comments

Is there a simple way I am overlooking to invoke a client side reload of data gathered by asyncConnect decorator?

kjanoudi avatar Feb 18 '16 06:02 kjanoudi

hi @kjanoudi Could you please describe more detailed your case? There is no such api to reload promises in asyncConnect decorator now However changing location would reload them

sars avatar Feb 18 '16 11:02 sars

Hi @sars, As to this topic, what would it take to expose that kind of API? I think it would expand the usability of the asyncConnect package exponentially if we can allow reloading of the data without a location/route change.

Also, unrelated but I'm not sure if you saw my post here, that may help me understand better: https://github.com/erikras/react-redux-universal-hot-example/pull/928#issuecomment-185550824

kjanoudi avatar Feb 18 '16 20:02 kjanoudi

@kjanoudi , what interface would you expect for such API? there is loadOnServer method that triggers loading

do you want to trigger just reloading of current route? or you want to trigger it for specific route?

sars avatar Feb 19 '16 11:02 sars

@sars Is the loadOnServer method able to be called from the client side? I was unclear, based on it's usage within the node.js code in the example, as well as the function name.

given this example:

@asyncConnect([{
  key: 'widgets',
  promise: ({helpers}) => helpers.client.get('/widget/load/param1/param2')
}])

It would be nice to be able to do something like pass in a dispatch method that would allow us to reload a prop based on it's key. Something like


import { loadAsync } from 'redux-async-connect';

handleClick(){
loadAsync('widgets')
}

Is that feasible?

kjanoudi avatar Feb 19 '16 15:02 kjanoudi

@kjanoudi the problem is that key is global now. This means that you can use asyncConnect for different components with same keys.

what promise in your case loadAsync('widgets') it should invoke? ...

I thought... may be it make sense to define keys and promises for them in one place, like..

reduxAsyncConnect.init({
  widgets: ({helpers}) => helpers.client.get('/widget/load/param1/param2')
})

or something like this... and then use them in components, like:

@asyncConnect([{
  key: 'widgets',
  deferred: true,
  shouldUpdate: ...
}])

in this case function loadAsync('widgets') would definitely make sense..

sars avatar Feb 23 '16 21:02 sars

@sars I was running under the impression that the keys would be/are unique. In that sense, a single key would always map to a single route/action.

kjanoudi avatar Feb 24 '16 03:02 kjanoudi