Skip to content

Commit

Permalink
Add React and ReactRouter
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nambrot committed Apr 1, 2015
1 parent 2277952 commit c805243
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ I'll try to keep this as concise as possible in a step-by-step guide of how I ap

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.

### 2. Setup basic React and Flux


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.

### Not Adressing

Expand Down
7 changes: 6 additions & 1 deletion app/assets/javascripts/client_application.cjsx
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
alert "I get loaded"
React = require('react')
Router = require('react-router')
routes = require('routes')

Router.run routes, Router.HistoryLocation, (Handler, state) ->
React.render(<Handler />, document.getElementById("reactContent"))
10 changes: 10 additions & 0 deletions app/assets/javascripts/components/posts/index.cjsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
React = require('react')

Index = React.createClass
displayName: "PostsIndex"
render: ->
<div>
<h3>Posts Index</h3>
</div>

module.exports = Index
10 changes: 10 additions & 0 deletions app/assets/javascripts/components/posts/show.cjsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
React = require('react')

Show = React.createClass
displayName: "PostShow"
render: ->
<div>
<h3>Posts Show</h3>
</div>

module.exports = Show
22 changes: 22 additions & 0 deletions app/assets/javascripts/routes.cjsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
React = require('react')
Router = require('react-router')

DefaultRoute = Router.DefaultRoute
Route = Router.Route

PostsIndex = require "components/posts/index"
PostShow = require "components/posts/show"

routes = (
<Route name="app" path="/">
<Route name="posts">
<Route name="post" path=":postId">
<DefaultRoute handler={PostShow} />
</Route>
<DefaultRoute handler={PostsIndex} />
</Route>
<DefaultRoute handler={PostsIndex} />
</Route>
)

module.exports = routes
3 changes: 2 additions & 1 deletion app/assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"json-loader": "*"
},
"dependencies": {

"react": "*",
"react-router": "*"
}
}
2 changes: 1 addition & 1 deletion app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ article {
}
}

#content {
#content, #reactContent {
margin: 12px auto;
max-width: 600px;

Expand Down
3 changes: 3 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<div id="content">
<%= yield %>
</div>
<div id="reactContent">

</div>

</div>

Expand Down

0 comments on commit c805243

Please sign in to comment.