darul75 / web-react

:diamond_shape_with_a_dot_inside: Another React Dev Kit with Webpack and NodeJS
https://react-web.herokuapp.com/
81 stars 8 forks source link

Motivation for getDataState() not inside HomeSection component? #3

Closed barrystaes closed 9 years ago

barrystaes commented 9 years ago

Looking at this starter kit now.. and see a great example of something that intrigues me:

The controller view HomeSection.jsx has a function to load state from store.

Why is it placed not inside the component, but as a (global) function next to it? AFAIK, there is nothing outside of the component that would need to be able to call it in the global scope.

darul75 commented 9 years ago

Indeed you are right and that was just inpired by great Alt example here :

https://github.com/goatslacker/alt/blob/master/examples/todomvc/js/components/TodoApp.react.js

Then this method should be static to component, do you have any suggestions of refactoring ?

barrystaes commented 9 years ago

I was just trying to understand the reason, but perhaps there is none.. if anyone reading this knows please do tell. :)

My diy kiss flux test (looks like yours) continues to work since ditching that global function: https://github.com/barrystaes/react-starter/commit/b5cfad300be474fc46c4c9225e036fd32c2839be#diff-60e809b1ec027a80a8f077712572fccb

barrystaes commented 9 years ago

Turns out there is a reason to have functions like this.

Apparently this is how JS objects exposed through modules can have "private" variables and functions.