Skip to content

Commit c805243

Browse files
committed
Add React and ReactRouter
Basic Setup of the routing and the Index/Show Components. Basically, for now we are trying to render the exact same thing but on the client side. The next step will require the loading of the data.
1 parent 2277952 commit c805243

File tree

8 files changed

+56
-4
lines changed

8 files changed

+56
-4
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ I'll try to keep this as concise as possible in a step-by-step guide of how I ap
1515

1616
Love the asset pipeline to death, but the lack of true models definitely gets noticable with larger amounts of client side code. We will be using Webpack to allow us to write modular code as well as use the great diversity of the NPM ecosystem.
1717

18+
### 2. Setup basic React and Flux
1819

19-
20+
We are going to set the barebones of the Flux architecture without thinking too much about the server part, for now, we will just fetch everything on demand.
2021

2122
### Not Adressing
2223

Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
alert "I get loaded"
1+
React = require('react')
2+
Router = require('react-router')
3+
routes = require('routes')
4+
5+
Router.run routes, Router.HistoryLocation, (Handler, state) ->
6+
React.render(<Handler />, document.getElementById("reactContent"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
React = require('react')
2+
3+
Index = React.createClass
4+
displayName: "PostsIndex"
5+
render: ->
6+
<div>
7+
<h3>Posts Index</h3>
8+
</div>
9+
10+
module.exports = Index
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
React = require('react')
2+
3+
Show = React.createClass
4+
displayName: "PostShow"
5+
render: ->
6+
<div>
7+
<h3>Posts Show</h3>
8+
</div>
9+
10+
module.exports = Show

app/assets/javascripts/routes.cjsx

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
React = require('react')
2+
Router = require('react-router')
3+
4+
DefaultRoute = Router.DefaultRoute
5+
Route = Router.Route
6+
7+
PostsIndex = require "components/posts/index"
8+
PostShow = require "components/posts/show"
9+
10+
routes = (
11+
<Route name="app" path="/">
12+
<Route name="posts">
13+
<Route name="post" path=":postId">
14+
<DefaultRoute handler={PostShow} />
15+
</Route>
16+
<DefaultRoute handler={PostsIndex} />
17+
</Route>
18+
<DefaultRoute handler={PostsIndex} />
19+
</Route>
20+
)
21+
22+
module.exports = routes

app/assets/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"json-loader": "*"
1717
},
1818
"dependencies": {
19-
19+
"react": "*",
20+
"react-router": "*"
2021
}
2122
}

app/assets/stylesheets/application.css.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ article {
5252
}
5353
}
5454

55-
#content {
55+
#content, #reactContent {
5656
margin: 12px auto;
5757
max-width: 600px;
5858

app/views/layouts/application.html.erb

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
<div id="content">
2222
<%= yield %>
2323
</div>
24+
<div id="reactContent">
25+
26+
</div>
2427

2528
</div>
2629

0 commit comments

Comments
 (0)