Skip to content
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

Reflux.listenTo's third augument defaultCallback #531

Closed
MAYDAY1993 opened this issue Aug 18, 2017 · 2 comments
Closed

Reflux.listenTo's third augument defaultCallback #531

MAYDAY1993 opened this issue Aug 18, 2017 · 2 comments

Comments

@MAYDAY1993
Copy link

hi,I looked through the docs about Reflux.listenTo's usages in here and find that there are two arguments:one is listenable,the other is callback,but later I find out that there exists a third argument meaning defaultCallback ,I can't find related docs ,only this pr : pr.
My problem is :what's the usage of defaultCallback,when to call this function and is there any ducuments to refer to?Thank you 😃

@eek
Copy link
Contributor

eek commented Oct 6, 2017

If you dig a bit in the code,

listenTo is made of function(listenable,callback,defaultCallback){

Where if defaultCallback exists it goes and fetches the initial state (fetchInitialState) from the listenable, and feeds the data back into defaultCallback

And fetchInitialState has the next explanation:

/**
 * Used in `listenTo`. Fetches initial data from a publisher if it has a `getInitialState` method.
 * @param {Action|Store} listenable The publisher we want to get initial state from
 * @param {Function|String} defaultCallback The method to receive the data
 */

So if the store you are about to listen to, has the getInitialState , you can pass defaultCallback to grab the data retuned from getInitialState and do something with it.

@MAYDAY1993
Copy link
Author

@eek thank you so much 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants