Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
99 additions
and
65 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict' | ||
var shoe = require('shoe') | ||
var AppDispatcher = require('../dispatcher/AppDispatcher') | ||
|
||
shoe('/echo') | ||
.on('connect', function () { | ||
console.log('[connected]') | ||
}) | ||
.on('data', function (chnk) { | ||
var data | ||
try { | ||
AppActionShoe.add(JSON.parse(chnk)) | ||
} catch (err) { | ||
console.log(err) | ||
} | ||
}) | ||
|
||
var AppActionShoe = module.exports = { | ||
add: function (data) { | ||
AppDispatcher.dispatch({ | ||
actionType: 'ADD' | ||
, data: data | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict' | ||
var React = require('react') | ||
var Item = require('./item') | ||
var AppStoreList = require('../stores/AppStoreList') | ||
var AppActionShoe = require('../actions/AppActionShoe') | ||
|
||
function setList () { | ||
return {list: AppStoreList.getList().reverse()} | ||
} | ||
|
||
var Box = React.createClass({ | ||
render: function () { | ||
var list = this.state.list | ||
return ( | ||
<ul id="result-list"> | ||
{list.map(function (data) { | ||
return <Item key={data.id} data={data} /> | ||
})} | ||
</ul> | ||
) | ||
} | ||
, getInitialState: function () { | ||
return setList() | ||
} | ||
, componentDidMount: function () { | ||
var me = this | ||
AppStoreList.on('change', function () { | ||
me.setState(setList()) | ||
}) | ||
} | ||
}) | ||
|
||
module.exports = Box |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
'use strict' | ||
var React = require('react') | ||
|
||
module.exports = React.createClass({ | ||
var Item = React.createClass({ | ||
render: function () { | ||
var tweet = this.props.data | ||
var user = tweet.user | ||
return ( | ||
<li className="tweet"> | ||
<div className="tweet-mata"> | ||
<img src={tweet.user.profile_image_url} /> | ||
<span>{tweet.user.screen_name + '/' + tweet.user.name}</span> | ||
<div className="tweet-meta"> | ||
<img src={user.profile_image_url} /> | ||
<span>{user.screen_name + '/' + user.name}</span> | ||
</div> | ||
<blockquote>{tweet.text}</blockquote> | ||
</li> | ||
) | ||
} | ||
}) | ||
|
||
module.exports = Item |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict' | ||
var Dispatcher = require('flux').Dispatcher | ||
module.exports = new Dispatcher |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
'use strict' | ||
var React = require('react') | ||
var CompoBox = require('./compo-box') | ||
var React = require('react') | ||
var Box = require('./components/box') | ||
|
||
React.render( | ||
<CompoBox url="/echo" /> | ||
<Box /> | ||
, document.querySelector('#content') | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict' | ||
var events = require('events') | ||
var AppDispatcher = require('../dispatcher/AppDispatcher') | ||
|
||
var list = [] | ||
|
||
var AppStoreList = new events.EventEmitter | ||
AppStoreList.getList = function () { | ||
return list | ||
} | ||
|
||
function add (data) { | ||
list.push(data) | ||
} | ||
|
||
AppDispatcher.register(function (payload) { | ||
var actionType = payload.actionType | ||
var data = payload.data | ||
if ('ADD' === actionType) { | ||
add(data) | ||
AppStoreList.emit('change') | ||
} | ||
}) | ||
|
||
module.exports = AppStoreList |
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