Last active
August 29, 2015 14:22
-
-
Save adregan/18de4f811e6a67384a0c to your computer and use it in GitHub Desktop.
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
import { Actions, Store, Flux } from 'flummox'; | |
class MessageActions extends Actions { | |
newMessage(content) { | |
return content; // automatically dispatched | |
} | |
} | |
class MessageStore extends Store { | |
constructor(flux) { | |
super(); | |
const messageActions = flux.getActions('messages'); | |
this.register(messageActions.newMessage, this.handleNewMessage); | |
this.messageCounter = 0; | |
this.state = {}; | |
} | |
handleNewMessage(content) { | |
const id = this.messageCounter++; | |
console.log(this.state); | |
this.setState({ | |
[id]: { | |
content, | |
id, | |
}, | |
}); | |
console.log(this.state); | |
} | |
} | |
export default class flux extends Flux { | |
constructor() { | |
super(); | |
this.createActions('messages', MessageActions); | |
this.createStore('messages', MessageStore, this); | |
} | |
} |
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
appRouter.get('*', (req, res) => { | |
const flux = new Flux; | |
flux.getActions('messages').newMessage('Hello, world!'); | |
var router = Router.create({ | |
routes: routes, | |
location: req.originalUrl, | |
}); | |
router.run(function (Handler) { | |
var content = React.renderToString(<Handler flux={flux} />); | |
return res.render('app.ejs', {content: content, flux: flux.serialize()}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment