Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
plh97 opened this issue Sep 24, 2017 · 0 comments
Open

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

plh97 opened this issue Sep 24, 2017 · 0 comments

Comments

@plh97
Copy link

plh97 commented Sep 24, 2017

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: [email protected]

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant