-
Notifications
You must be signed in to change notification settings - Fork 879
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add playground for React Hot Loader 2
- Loading branch information
Showing
4 changed files
with
84 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,4 @@ | ||
react-hot-boilerplate | ||
===================== | ||
|
||
The minimal dev environment to enable live-editing React components. | ||
|
||
### Usage | ||
|
||
``` | ||
npm install | ||
npm start | ||
open http://localhost:3000 | ||
``` | ||
|
||
Now edit `src/App.js`. | ||
Your changes will appear without reloading the browser like in [this video](http://vimeo.com/100010922). | ||
|
||
### Linting | ||
|
||
This boilerplate project includes React-friendly ESLint configuration. | ||
|
||
``` | ||
npm run lint | ||
``` | ||
|
||
### Using `0.0.0.0` as Host | ||
|
||
You may want to change the host in `server.js` and `webpack.config.js` from `localhost` to `0.0.0.0` to allow access from same WiFi network. This is not enabled by default because it is reported to cause problems on Windows. This may also be useful if you're using a VM. | ||
|
||
### Missing Features | ||
|
||
This boilerplate is purposefully simple to show the minimal configuration for React Hot Loader. For a real project, you'll want to add a separate config for production with hot reloading disabled and minification enabled. You'll also want to add a router, styles and maybe combine dev server with an existing server. This is out of scope of this boilerplate, but you may want to look into [other starter kits](https://github.com/gaearon/react-hot-loader/blob/master/docs/README.md#starter-kits). | ||
|
||
### Dependencies | ||
|
||
* React | ||
* Webpack | ||
* [webpack-dev-server](https://github.com/webpack/webpack-dev-server) | ||
* [babel-loader](https://github.com/babel/babel-loader) | ||
* [react-hot-loader](https://github.com/gaearon/react-hot-loader) | ||
|
||
### Resources | ||
|
||
* [Demo video](http://vimeo.com/100010922) | ||
* [react-hot-loader on Github](https://github.com/gaearon/react-hot-loader) | ||
* [Integrating JSX live reload into your workflow](http://gaearon.github.io/react-hot-loader/getstarted/) | ||
* [Troubleshooting guide](https://github.com/gaearon/react-hot-loader/blob/master/docs/Troubleshooting.md) | ||
* Ping dan_abramov on Twitter or #reactjs IRC | ||
This branch is a playground for the future version of React Hot Loader. Right now it doesn't even use it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import { createProxy, getForceUpdate } from 'react-proxy'; | ||
|
||
if (!window.__reactProxies) { | ||
window.__reactProxies = {}; | ||
} | ||
|
||
const forceUpdate = getForceUpdate(React); | ||
|
||
export default function hot(id, ...dependencies) { | ||
id = [id, ...dependencies.map(dep => dep.__proxyId || dep)].join('$$$'); | ||
|
||
return function (ReactClass) { | ||
if (window.__reactProxies[id]) { | ||
console.info(`updating ${id}`); | ||
const instances = window.__reactProxies[id].update(ReactClass); | ||
requestAnimationFrame(() => { | ||
instances.forEach(forceUpdate); | ||
}); | ||
} else { | ||
console.info(`creating ${id}`); | ||
window.__reactProxies[id] = createProxy(ReactClass); | ||
} | ||
|
||
let ProxyClass = window.__reactProxies[id].get(); | ||
ProxyClass.__proxyId = id; | ||
return ProxyClass; | ||
}; | ||
} |