-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #202 from optimizely/jordan/add-replace-stores
Add replaceStores
- Loading branch information
Showing
21 changed files
with
412 additions
and
2 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
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,9 @@ | ||
TODO for `1.3.0` | ||
=== | ||
|
||
- [ ] add documentation for all new reactor options | ||
- [ ] link the nuclear-js package from the hot reloadable example | ||
- [ ] link `0.3.0` of `nuclear-js-react-addons` in hot reloadable example | ||
- [ ] add `nuclear-js-react-addons` link in example and documentation | ||
- [ ] publish doc site | ||
|
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,7 @@ | ||
{ | ||
presets: ['es2015', 'react'], | ||
plugins: ['transform-decorators-legacy', 'syntax-decorators'], | ||
ignore: [ | ||
'**/nuclear-js-react-addons/**', | ||
] | ||
} |
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,2 @@ | ||
dist | ||
node_modules |
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,38 @@ | ||
NuclearJS Hot Reloading | ||
=== | ||
|
||
NuclearJS supports hot reloading of stores. Using the webpack Hot Module Replacement simply code like this to wherever your stores are registered. | ||
|
||
|
||
```js | ||
import { Reactor } from 'nuclear-js' | ||
import * as stores from './stores' | ||
|
||
const reactor = new Reactor({ | ||
debug: true, | ||
}) | ||
reactor.registerStores(stores) | ||
|
||
if (module.hot) { | ||
// Enable webpack hot module replacement for stores | ||
module.hot.accept('./stores', () => { | ||
reactor.replaceStores(require('./stores')) | ||
}) | ||
} | ||
|
||
export default reactor | ||
``` | ||
|
||
## Running Example | ||
|
||
``` | ||
npm install | ||
npm start | ||
``` | ||
|
||
Go to [http://localhost:3000](http://localhost:3000) | ||
|
||
## Inpsiration & Thanks | ||
|
||
Big thanks to [redux](https://github.com/rackt/redux) and [react-redux](https://github.com/rackt/react-redux) for proving out this architecture | ||
and creating simple APIs to accomplish hot reloading. |
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,12 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>NuclearJS Hot Reloading</title> | ||
</head> | ||
|
||
<body style="padding: 30px;"> | ||
<div id="root"></div> | ||
<script src="http://localhost:3000/dist/app.js"></script> | ||
</body> | ||
</html> | ||
|
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,30 @@ | ||
{ | ||
"name": "nuclear-js-hot-reloading-example", | ||
"version": "1.0.0", | ||
"description": "Hot Reloading with NuclearJS", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "node webpack-server.js", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "Jordan Garcia", | ||
"license": "MIT", | ||
"dependencies": { | ||
"react": "^0.14.3", | ||
"react-dom": "^0.14.3" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.3.17", | ||
"babel-core": "^6.3.21", | ||
"babel-loader": "^6.2.0", | ||
"babel-plugin-syntax-decorators": "^6.3.13", | ||
"babel-plugin-transform-decorators": "^6.3.13", | ||
"babel-plugin-transform-decorators-legacy": "^1.3.4", | ||
"babel-preset-es2015": "^6.3.13", | ||
"babel-preset-react": "^6.3.13", | ||
"babel-preset-stage-0": "^6.3.13", | ||
"react-hot-loader": "^1.3.0", | ||
"webpack": "^1.12.9", | ||
"webpack-dev-server": "^1.12.1" | ||
} | ||
} |
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,7 @@ | ||
export function increment(reactor) { | ||
reactor.dispatch('increment') | ||
} | ||
|
||
export function decrement(reactor) { | ||
reactor.dispatch('decrement') | ||
} |
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,24 @@ | ||
import React, { Component, PropTypes } from 'react' | ||
|
||
class Counter extends Component { | ||
render() { | ||
const { increment, decrement, counter } = this.props | ||
return ( | ||
<p> | ||
Clicked: {counter} times | ||
{' '} | ||
<button onClick={increment}>+</button> | ||
{' '} | ||
<button onClick={decrement}>-</button> | ||
</p> | ||
) | ||
} | ||
} | ||
|
||
Counter.propTypes = { | ||
increment: PropTypes.func.isRequired, | ||
decrement: PropTypes.func.isRequired, | ||
counter: PropTypes.number.isRequired | ||
} | ||
|
||
export default Counter |
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,18 @@ | ||
import React, { Component } from 'react' | ||
import { connect } from 'nuclear-js-react-addons' | ||
import Counter from '../components/Counter' | ||
import { increment, decrement } from '../actions/counter' | ||
|
||
@connect(props => ({ | ||
counter: ['counter'] | ||
})) | ||
export default class AppContainer extends Component { | ||
render() { | ||
let { reactor, counter } = this.props | ||
return <Counter | ||
counter={counter} | ||
increment={increment.bind(null, reactor)} | ||
decrement={decrement.bind(null, reactor)} | ||
/> | ||
} | ||
} |
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,12 @@ | ||
import React from 'react' | ||
import { render } from 'react-dom' | ||
import { Provider } from 'nuclear-js-react-addons' | ||
import App from './containers/App' | ||
import reactor from './reactor' | ||
|
||
render( | ||
<Provider reactor={reactor}> | ||
<App /> | ||
</Provider>, | ||
document.getElementById('root') | ||
) |
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,16 @@ | ||
import { Reactor } from 'nuclear-js' | ||
import * as stores from './stores' | ||
|
||
const reactor = new Reactor({ | ||
debug: true, | ||
}) | ||
reactor.registerStores(stores) | ||
|
||
if (module.hot) { | ||
// Enable Webpack hot module replacement for stores | ||
module.hot.accept('./stores', () => { | ||
reactor.replaceStores(require('./stores')) | ||
}) | ||
} | ||
|
||
export default reactor |
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,11 @@ | ||
import { Store } from 'nuclear-js' | ||
|
||
export default new Store({ | ||
getInitialState() { | ||
return 0 | ||
}, | ||
initialize() { | ||
this.on('increment', (state) => state + 1) | ||
this.on('decrement', (state) => state - 1) | ||
} | ||
}) |
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,5 @@ | ||
import counter from './counter' | ||
|
||
export { | ||
counter | ||
} |
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,15 @@ | ||
var webpack = require('webpack'); | ||
var WebpackDevServer = require('webpack-dev-server'); | ||
var config = require('./webpack.config'); | ||
|
||
new WebpackDevServer(webpack(config), { | ||
publicPath: config.output.publicPath, | ||
hot: true, | ||
historyApiFallback: true | ||
}).listen(3000, 'localhost', function (err, result) { | ||
if (err) { | ||
console.log(err); | ||
} | ||
|
||
console.log('Listening at localhost:3000'); | ||
}); |
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,28 @@ | ||
var path = require('path'); | ||
var webpack = require('webpack'); | ||
|
||
module.exports = { | ||
entry: [ | ||
'webpack-dev-server/client?http://localhost:3000', | ||
'webpack/hot/only-dev-server', | ||
'./src/main' | ||
], | ||
output: { | ||
path: path.join(__dirname, 'public', 'dist'), | ||
filename: 'app.js', | ||
publicPath: 'http://localhost:3000/dist/' | ||
}, | ||
plugins: [ | ||
new webpack.HotModuleReplacementPlugin() | ||
], | ||
module: { | ||
loaders: [ | ||
{ | ||
test: /\.js$/, | ||
exclude: /node_modules/, | ||
loaders: ['react-hot', 'babel-loader'], | ||
} | ||
] | ||
}, | ||
devtool: 'eval', | ||
} |
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
Oops, something went wrong.