reactjs/react-rails — pull request #84 by olance (2014-08-30 01:14:17+00:00)
Title: Remove need for global workaround and make Browserify happy

Define `self` and `window` global objects in the combined JS code so that:

* components in Coffee files can really use `window` instead of using `global` to become accessible, thus removing the need for the `var self, window, global = global || window || self;` trick in `components.js` to have the code work both on server & clients
* components/files packaged as CommonJS modules by browserify (using browserify-rails for instance) can successfully use `global` if they want to

For this second point, this fix is necessary because of the self-calling function browserify uses to wrap code that accesses the `global` variable:

```ruby
(function (global){
global.MyComponent = React.createClass({ ... });
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
```
If `window` was used instead of `global`, it would still need the fix when compiling on the server, as `window` would not be defined otherwise.

I have not included tests, as I am not sure how to test this...

Maybe what could serve for testing would just be to remove the `var self, window, global = global || window || self;` line from `components.js` in the dummy app, change `global.Todo = Todo` to `window.Todo = Todo` in `app/assets/javascripts/components/Todo.js.jsx.coffee` and be satisfied that tests are still successful?

Open to suggestions to complete the PR :)