import React, { Component } from 'react'
var store = {
//订阅
list:[],
subscribe(callback){ //收集回调函数
this.list.push(callback)
},
//发布
publish(data){ //回调 这些回调函数
this.list.forEach(callback=>{
callback(data)
})
}
}
class WeixinUser{ // 微信用户订阅
constructor(){
store.subscribe(this.message)
}
message(data){
console.log("用户收到消息了",data)
}
}
class WexinAuthor{ //微信作者发布信息
send(data){
store.publish(data)
}
}
var user = new WeixinUser()
var author = new WexinAuthor()
setTimeout(()=>{
author.send("男人看沉默")
},2000)