Skip to content

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

@plh97

Description

@plh97
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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions