Fri Jul 21 2017
Copied to clipboard! Copy reply
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
// Pubsub for commication between preact components
var Pubsub = function() {
  this.topics = {}

  this.on = function(topicname, fn) {
    if (!this.topics[topicname])
      this.topics[topicname] = []
    this.topics[topicname].push(fn)
  }

  this.trigger = function(topicname, args) {
    if (!this.topics[topicname]) return

    this.topics[topicname].forEach(fn => fn(args) )
  }
}

var pubsub = new Pubsub()
export default pubsub