choo-hooks

1.1.3 • Public • Published

choo-hooks stability

npm version build status downloads js-standard-style

Hook into Choo's events and timings. Useful to create loggers, analytics and more.

Usage

var Hooks = require('choo-hooks')
var choo = require('choo')
 
var app = choo()
app.use(function (state, emitter) {
  var hooks = Hooks(emitter)
  hooks.on('event', function (eventName, timing, data) {
    console.log(eventName + ':', timing.duration + 'ms', data)
  })
 
  hooks.on('unhandled', function (eventName, data) {
    console.error('No listeners for ' + eventName)
  })
})

API

hooks = Hooks(emitter)

Create a new Choo Hooks instance.

hook.on('log:trace', cb(…args))

hook.on('log:debug', cb(…args))

hook.on('log:info', cb(…args))

hook.on('log:warn', cb(…args))

hook.on('log:error', cb(…args))

hook.on('log:fatal', cb(…args))

Listen for log events.

hook.on('service-worker', cb(data))

Listen for service worker event.

hook.on('event', cb(eventName, timing, data))

Called for events implemented at the application layer.

hook.on('unhandled', cb(eventName, data))

Called whenever an event is emitted, and there is no handler available.

hook.on('DOMContentLoaded', cb(timing))

Called whenever the DOM has loaded. Returns the window.performance.timing object.

hook.on('render', cb(timings))

Called whenever Choo renders. Returns an object with the render and morph properties.

hook.on('resourceTimingBufferFull', cb())

Called whenever the browser's resource timing buffer has filled up.

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.3
    37
    • latest

Version History

Package Sidebar

Install

npm i choo-hooks

Weekly Downloads

28

Version

1.1.3

License

MIT

Unpacked Size

8.44 kB

Total Files

5

Last publish

Collaborators

  • mreinstein
  • benlyn
  • s3ththompson
  • yoshuawuyts
  • bret
  • lrlna
  • yerkopalma
  • juliangruber
  • timwis
  • ahdinosaur
  • toddself
  • sethvincent
  • maxogden
  • shama
  • freeman-lab
  • feross
  • emilbayes
  • colingourlay
  • jameskyburz
  • almost
  • slaskis
  • ungoldman
  • graforlock
  • tornqvist
  • amongiants
  • goto-bus-stop
  • mafintosh