im-js / im.js

一个基于 react-native + mobx + socket.io + node 的仿微信 JS-Wechat

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

我还在弄web版的聊天室,mobx和socket.io如何结合

plh97 opened this issue · comments

commented
class TodoStore {
	@observable list = []
	@observable fetched = false
	@action emit = (url) => {
		this.fetched = true
		socket.emit(url)
	}

	@computed get on(){
		socket.on('get list',(json)=>{
			this.fetched = false
			this.list = json.map((index,i)=>{
				return new List(index)
			})
		})
	}
}

mobx正常模式没问题,严格模式下

[mobx] Invariant failed: Since strict-mode is enabled, changing observed observable values outside actions is not allowed. Please wrap the code in an `action` if this change is intended. Tried to modify: TodoStore@1.fetched

mobx一直给我报错,我把接收socket.on函数放在外面,接收函数就根本不会触发。想知道你是如何处理好客户端的socket的发送与接收的。。。。
socket的接收是不是应该放在组件里面作为一个时刻可以接收信息的可以被任意随时触发的XXX?