brocoders / redux-async-connect

It allows you to request async data, store them in redux state and connect them to your react component.
645 stars 103 forks source link

How to invoke on client side? #41

Open kjanoudi opened 8 years ago

kjanoudi commented 8 years ago

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

sars commented 8 years ago

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

kjanoudi commented 8 years ago

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

sars commented 8 years ago

@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?

kjanoudi commented 8 years ago

@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?

sars commented 8 years ago

@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..

kjanoudi commented 8 years ago

@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.