bloody-functionhook

0.0.0 • Public • Published

function hook

Build Status

browser support

install

$ npm install bloody-functionhook

require

var hook = require("bloody-functionhook")

api

hook(object, propertyName) > notifier

replaces object[propertyName] by the hook function, and returns a notifier.

notifier

notifier.on(event, cb)
  • "arguments" fires when the arguments are accessible to the hook function
  • "error" fires if an error occurred
  • "call" fires when the function is called
  • "return" fires when the function has a result

notifier.count (int)

the times the function was called

notifier.emit("destroy")

removes the hook

example

var view = cornea.extend({
  getInitialData : function(){
    return {
      foo : ""
    }
  },
  template : function(data){
    return "<div></div>"
  }
})
 
var notifier = hook(view, "template")
var data = {
  foo : "bar"
}
notifier.on("arguments", function(args){
  test.equal(args[0], data, "data is passed")
  test.end()
})
view.update(data)

Readme

Keywords

none

Package Sidebar

Install

npm i bloody-functionhook

Weekly Downloads

0

Version

0.0.0

License

MIT

Last publish

Collaborators

  • bloodyowl