, . @matthewatabet @abguy, https://github.com/luskhq/redux-ws , , Redux Thunk, - .
, , Github, . socket.io, - .
, dispatch addNewItemSocket:
<RaisedButton
label="Click to add!" primary={true}
onTouchTap={ () => {
const newItem = ReactDOM.findDOMNode(this.refs.newTodo.input).value
newItem === "" ? alert("Item shouldn't be blank")
: dispatch(addNewItemSocket(socket,items.size,newItem))
{}
ReactDOM.findDOMNode(this.refs.newTodo.input).value = ""
}
}
/>
addNewItemSocket :
export const addNewItemSocket = (socket,id,item) => {
return (dispatch) => {
let postData = {
id:id+1,
item:item,
completed:false
}
socket.emit('addItem',postData)
}
}
, :
socket.on('itemAdded',(res)=>{
console.dir(res)
dispatch(AddItem(res))
})
actoins AddItem :
export const AddItem = (data) => ({
type: "ADD_ITEM",
item: data.item,
itemId:data.id,
completed:data.completed
})
This is still new to me, so any feedback is welcome. I will also write a PR from https://github.com/luskhq/redux-ws to give an example given there.
source
share