Skip to content

Commit

Permalink
Set up basic Flux with Stores and Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
nambrot committed Apr 1, 2015
1 parent 0e1e049 commit 715a1a4
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 5 deletions.
5 changes: 5 additions & 0 deletions app/assets/javascripts/actions/post.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Actions = require('flummox').Actions

class PostActions extends Actions

module.exports = PostActions
6 changes: 5 additions & 1 deletion app/assets/javascripts/client_application.cjsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
React = require('react')
Router = require('react-router')
routes = require('routes')
Flux = require('flux')
FluxComponent = require('flummox/component')

flux = new Flux()
Router.run routes, Router.HistoryLocation, (Handler, state) ->
React.render(<Handler />, document.getElementById("reactContent"))
handler = <FluxComponent flux={flux} render={ => <Handler />}></FluxComponent>
React.render(handler, document.getElementById("reactContent"))
11 changes: 11 additions & 0 deletions app/assets/javascripts/flux.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Flummox = require('flummox').Flummox
PostsStore = require('stores/post')
PostActions = require('actions/post')

class AppFlux extends Flummox
constructor: ->
super()
@createActions 'posts', PostActions
@createStore 'posts', PostsStore, this

module.exports = AppFlux
3 changes: 0 additions & 3 deletions app/assets/javascripts/posts.coffee

This file was deleted.

15 changes: 15 additions & 0 deletions app/assets/javascripts/stores/post.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Store = require('flummox').Store
Immutable = require('immutable')

getDefaultState = ->
{ posts: Immutable.OrderedMap(), didFetchAll: false }

class PostsStore extends Store
constructor: (flux) ->
super()

postActionIds = flux.getActionIds('posts')
@state = getDefaultState()
@flux = flux

module.exports = PostsStore
4 changes: 3 additions & 1 deletion app/assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
},
"dependencies": {
"react": "*",
"react-router": "*"
"react-router": "*",
"immutable": "*",
"flummox": "*"
}
}

0 comments on commit 715a1a4

Please sign in to comment.