Git Product home page Git Product logo

choo-hooks's Introduction

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

choo-hooks's People

Contributors

yoshuawuyts avatar ungoldman avatar toddself avatar bcomnes avatar netopwibby avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.