-
Notifications
You must be signed in to change notification settings - Fork 0
/
code-reflux-es5only.js
49 lines (45 loc) · 1.13 KB
/
code-reflux-es5only.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"use strict"
require("./node_modules/bootstrap/dist/css/bootstrap.min.css")
import React, { Component, PropTypes, DefaultProps } from 'react'
import ReactDOM from 'react-dom'
import Reflux from 'reflux'
// Reflux: action
var loadMessages = Reflux.createAction()
// Reflux: store
var messageStore = Reflux.createStore({
init: function() {
this.listenTo(loadMessages, 'onLoadMessages')
},
onLoadMessages: function(url){
var _this = this
setTimeout(function(){
_this.trigger([{name: 'Azat', message: 'React rocks!'}])
}, 1000)
}
})
var Content = React.createClass({
componentWillMount:function(){
loadMessages()
},
componentDidMount: function(){
messageStore.listen(this.update)
},
update: function(messages){
return this.setState({messages: messages})
},
render: function() {
return (
<div className="well">
<p>
{(this.state && this.state.messages.length) ?
this.state.messages[0]['name'] + ': '
+ this.state.messages[0]['message'] : ''}
</p>
</div>
)
}
})
ReactDOM.render(
<Content />,
document.getElementById('content')
)