How to use the nanobus.prototype function in nanobus

To help you get started, we’ve selected a few nanobus examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hypermodules / hyperamp / renderer / audio / audio-player.js View on Github external
this._endedListener = this.audio.addEventListener('ended', function () {
    if (!self.seeking) self.emit('ended')
  })

  this._timeListener = this.audio.addEventListener('timeupdate', function (ev) {
    if (self.seeking) return
    var timeupdate = Math.floor(self.audio.currentTime)
    if (self.timeupdate === timeupdate) return
    self.timeupdate = timeupdate
    self.emit('timeupdate', self.timeupdate)
  })

  this.emit('initialized', this)
}

AudioPlayer.prototype = Object.create(Nanobus.prototype)

AudioPlayer.prototype.seekDebounce = function () {
  this.seeking = true
  if (this.seekDebounceTimer) clearTimeout(this.seekDebounceTimer)
  var self = this
  this.seekDebounceTimer = setTimeout(function () {
    self.emit('debounce cleared')
    self.seeking = false
    self.seekDebounceTimer = null
    // TODO: check if we are at the end and we lost the endedEvent
  }, 1000)
}

AudioPlayer.prototype.queue = function (newIndex) {
  this.currentIndex = newIndex
  var key = this.trackOrder[this.currentIndex]
github choojs / nanostate / index.js View on Github external
Nanostate.prototype.emit = function (eventName) {
  var nextState = this._next(eventName)
  assert.ok(nextState, 'nanostate.emit: invalid transition' + this.state + '->' + eventName)

  if (this._submachine && Object.keys(this.transitions).indexOf(nextState) !== -1) {
    this._unregister()
  }

  this.state = nextState
  Nanobus.prototype.emit.call(this, nextState)
}
github choojs / nanostate / index.js View on Github external
module.exports = Nanostate

function Nanostate (initialState, transitions) {
  if (!(this instanceof Nanostate)) return new Nanostate(initialState, transitions)
  assert.equal(typeof initialState, 'string', 'nanostate: initialState should be type string')
  assert.equal(typeof transitions, 'object', 'nanostate: transitions should be type object')

  this.transitions = transitions
  this.state = initialState
  this.submachines = {}
  this._submachine = null

  Nanobus.call(this)
}

Nanostate.prototype = Object.create(Nanobus.prototype)

Nanostate.prototype.constructor = Nanostate

Nanostate.prototype.emit = function (eventName) {
  var nextState = this._next(eventName)
  assert.ok(nextState, 'nanostate.emit: invalid transition' + this.state + '->' + eventName)

  if (this._submachine && Object.keys(this.transitions).indexOf(nextState) !== -1) {
    this._unregister()
  }

  this.state = nextState
  Nanobus.prototype.emit.call(this, nextState)
}

Nanostate.prototype.event = function (eventName, machine) {
github lrlna / nanoidb / index.js View on Github external
module.exports = Nanoidb

function Nanoidb (name, version) {
  if (!(this instanceof Nanoidb)) return new Nanoidb(name, version)
  Nanobus.call(this, 'Nanoidb')

  this._name = name
  this._version = version

  assert.equal(typeof name, 'string', 'Nanoidb: name should be type string')
  assert.equal(typeof version, 'number', 'Nanoidb: version should be type number')

  this.upgrade(this._version)
}

Nanoidb.prototype = Object.create(Nanobus.prototype)

Nanoidb.prototype.upgrade = function (version) {
  assert.equal(typeof version, 'number', 'Nanoidb.upgrade: version should be type number')
  this._version = version

  this.request = window.indexedDB.open(this._name, this._version)

  this.request.onerror = this.onerror.bind(this)
  this.request.onsuccess = this.onsuccess.bind(this)
  this.request.onupgradeneeded = this.onupgradeneeded.bind(this)
}

Nanoidb.prototype.onsuccess = function (event) {
  var storeNames = event.target.result.objectStoreNames
  this.db = event.target.result

nanobus

Tiny message bus

MIT
Latest version published 4 years ago

Package Health Score

59 / 100
Full package analysis

Popular nanobus functions