node-pluggable
v0.3.3
Published
Add your Hook more easily.
Downloads
25
Readme
node-pluggable
Add your Hook more easily.
Demo
Installation
npm install node-pluggable
API
Pluggable = require 'node-pluggable'
plugin = new Pluggable()use([match_param ,] hook_callback...) => this
plugin.use('article.create', (article, next) ->
article.hook = 'article.create'
next()
)- this method is similar to connect
match_parammust bestringorregexhook_callbackwill be called whenparamis matched
run(param, hook_callback_params...[, callback]) => this
article =
title: 'title'
author: 'author'
content: 'content'
plugin.run 'article.create', article, ->
console.log articleparamwill match withmatch_param, which must bestringhook_callback_paramswill be send tohook_callback
bind(hook_name, hook_callback...) => this
plugin.bind 'article.update', (article) ->
console.log article
, (article) ->
console.log article.lengthhook_callbackwill be called when event be emitted
on(hook_name, hook_callback) => this
plugin.on 'article.update', (article) ->
console.log article- similar to
bind
emit(hook_name, data) => this
plugin.emit 'article.update', 'just a message.'
- emit an event
