javascript - React.js & Flux - where is the best place to register Websocket event (receive data) -
i'm trying write simple application should display list of items received firebase db, using websockets. receive data should listen firebase events, this:
var ref = new firebase("firebase-url-here"); ref.on('value', function(snap) { console.log(snap.val()); }); my question - correct location register event?
i read great article flux - in comments section there answer facebook engineer saying receiving data via store's getdata method. on other hand, on facebook's todolist tutorial there option 'handleserveraction' should handle server actions. understand concept actions should dispatched view , server (as view actions , server actions).
view actions dispatched user interactions on view file. not understand place dispatch server actions (assuming want use 'handleserveraction' method)
that's how i'd (in case of flux): should put websocket web api module. create socket init action (to initialize websocket) , push action (to send data via socket). make web api module dispatch action on data income, listen action in store , update store once data. can dispatch init action within root component , listen store changes in components need data. can dispatch push action when need send data on socket.
Comments
Post a Comment