Skip to content

Commit 0164909

Browse files
committed
Add option to disable server-side rendering
Plus some misc. updates/cleanups.
1 parent fa3a56f commit 0164909

File tree

5 files changed

+27
-18
lines changed

5 files changed

+27
-18
lines changed

examples/examples.cjsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = React.createClass
88
margin: 10
99

1010
render: ->
11-
<div style={"max-width":'1200px', margin:'0 auto'}>
11+
<div style={"maxWidth":'1200px', margin:'0 auto'}>
1212
<h1>react-component-gallery</h1>
1313
<a href="https://github.com/KyleAMathews/react-component-gallery">Code on Github</a>
1414
<p>Create a perfect component gallery every time whatever the size of the
@@ -75,7 +75,7 @@ module.exports = React.createClass
7575
background: "rgba(0,0,0,0.5)"
7676
bottom: 0
7777
left: 0
78-
"line-height": "30px"
78+
"lineHeight": "30px"
7979
height: "30px"
8080
padding: "0 10px"
8181
color: "white"

examples/index.cjsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
React = require('react')
22
Examples = require './examples'
33

4-
React.renderComponent(<Examples />, document.body)
4+
React.render(<Examples />, document.body)

package.json

+10-9
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77
"url": "https://github.com/KyleAMathews/react-component-gallery/issues"
88
},
99
"dependencies": {
10-
"react-component-width-mixin": "^1.1.0"
10+
"react-component-width-mixin": "^1.1.2"
1111
},
1212
"devDependencies": {
13-
"cjsx-loader": "^0.3.0",
13+
"cjsx-loader": "^1.1.0",
1414
"coffee-loader": "^0.7.2",
15-
"coffee-react": "^1.0.2",
15+
"coffee-react": "^2.1.2",
1616
"coffee-script": "^1.8.0",
1717
"css-loader": "^0.9.0",
18-
"gulp": "^3.8.8",
19-
"react-hot-loader": "^0.4.5",
20-
"style-loader": "^0.8.1",
18+
"gulp": "^3.8.10",
19+
"react-hot-loader": "^0.5.0",
20+
"style-loader": "^0.8.2",
2121
"underscore": "^1.7.0",
22-
"webpack": "^1.4.4",
23-
"webpack-dev-server": "^1.6.5"
22+
"webpack": "^1.4.13",
23+
"webpack-dev-server": "^1.6.6"
2424
},
2525
"homepage": "https://github.com/KyleAMathews/react-component-gallery",
2626
"keywords": [
@@ -38,6 +38,7 @@
3838
"url": "https://github.com/KyleAMathews/react-component-gallery.git"
3939
},
4040
"scripts": {
41-
"test": "echo \"Error: no test specified\" && exit 1"
41+
"test": "echo \"Error: no test specified\" && exit 1",
42+
"watch": "./node_modules/.bin/webpack-dev-server --hot"
4243
}
4344
}

src/index.cjsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,22 @@ module.exports = React.createClass
77

88
propTypes:
99
children: React.PropTypes.any.isRequired
10+
disableServerRender: React.PropTypes.bool
1011

1112
getDefaultProps: ->
1213
margin: 10
1314
targetWidth: 200
1415
widthHeightRatio: 1
16+
disableServerRender: false
1517

1618
render: ->
17-
if @state.componentWidth isnt 0
19+
# If we don't know the component width, there's nothing we can do.
20+
if @state.componentWidth is 0
21+
<div />
22+
# If we're server rendering and the user has disalbed server rendering.
23+
else if not @isMounted() and @props.disableServerRender
24+
<div />
25+
else
1826
[componentWidth, componentsPerRow] = @calculateComponentWidth()
1927
return (
2028
<div className="component-gallery #{@props.className}" style={{overflow: "hidden"}}>
@@ -44,8 +52,6 @@ module.exports = React.createClass
4452
)}
4553
</div>
4654
)
47-
else
48-
<div />
4955

5056
calculateComponentWidth: ->
5157
_calcComponentWidth = (adjustComponentsPerRow = 0) =>

webpack.config.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
var path = require('path');
22
var webpack = require('webpack');
33

4-
54
module.exports = {
65
entry: [
76
"webpack-dev-server/client?http://0.0.0.0:8080",
8-
'webpack/hot/dev-server',
7+
'webpack/hot/only-dev-server',
98
'./examples/index'
109
],
11-
contentBase: './examples/',
10+
devServer: {
11+
contentBase: './examples/'
12+
},
1213
devtool: "eval",
1314
debug: true,
1415
output: {
@@ -20,6 +21,7 @@ module.exports = {
2021
},
2122
plugins: [
2223
new webpack.HotModuleReplacementPlugin(),
24+
new webpack.NoErrorsPlugin(),
2325
new webpack.IgnorePlugin(/un~$/)
2426
],
2527
resolve: {

0 commit comments

Comments
 (0)