Search code examples
javascriptreactjsfluxrefluxjs

Reflux callback after store is changed


I'm working on Chrome Extension using React.js and Reflux. Now I need to notify all parts of extension about changes when store is updated with one callback.

Something like:

function(newStore){
  chrome.runtime.sendMessage({action: 'updateStore', store: newStore});
}

Where is the point in Reflux for adding such callback?


Solution

  • I haven't built a chrome extension using Reflux but in general the pattern is to call:

    store.listen(function(data) {
        // data is whatever your store invoked by saying this.trigger(...)
    });
    

    The callback function will be invoked whenever your store calls trigger with new data.