websockets在Alt做助焊剂的方式适合哪些方面?什么应该负责将套接字消息转换为动作,反之亦然?
编辑:
这就是我现在所拥有的似乎有用的东西,但如果你有适合自己的做事方式,请发一个答案。
var alt = require('../alt');
var UserActions = require('../actions/UserActions');
var socket = io();
socket.on("user", function(user) {
UserActions.addUser(user);
});
class UserStore {
constructor() {
this.users = [{id:1, name: "michael"}, { id:2, name: "lauren"}];
this.bindListeners({
handleUpdateUsers: UserActions.UPDATE_USERS,
handleAddUser: UserActions.ADD_USER
});
}
handleUpdateUsers(users) {
this.users = users;
}
handleAddUser(user) {
this.users.push(user);
}
}
module.exports = alt.createStore(UserStore, 'UserStore');