import Taro from "@tarojs/taro";

const KEY = 'ARTICLES_EVENTS'

interface Data {
  id: number
  view: number
}

function recordsAdd(data: Data) {
  Taro.eventCenter.trigger(KEY + data.id, data)
}

function recordsOn(id: number, fn: (data: Data) => void) {
  Taro.eventCenter.on(KEY + id, fn)
}

function off(id: number) {
  Taro.eventCenter.off(KEY + id)
}

const ArticlesEvent = {
  recordsAdd,
  recordsOn,
  off
}

export default ArticlesEvent
