match-event
Extend an event emitter to use string and regex patterns to listen for matching events.
Install with npm
$ npm i match-event --save
Usage
Example using only the component-emitter and a simple object.
var Emitter = ;var matchEvent = ;var app = ;app; app; app;
Example using base-methods and adding match-event
in the constructor.
var Base = ; // Create an app inheriting from Base// component-emitter is used in base-methods so// it's not needed here. { Base; // use match-event as a plugin this;} Base; var app = ;app; app;
Example using base-methods and adding match-event
to an instance of MyApp
.
var Base = ; // Create an app inheriting from Base// component-emitter is used in base-methods so// it's not needed here. { Base;} Base; var app = ;app; app; app;
API
Register an event listener that will only be called when a string is passed that matches the given regex or string literal.
Params
event
{String}: Event name to pass to the emitteron
method.re
{String|RegExp}: String or RegExp pattern to match.fn
{Function}: Event listener function to pass to the emitteron
method.returns
{Object}: Returnthis
for chaining.
Related projects
- base-methods: Starter for creating a node.js application with a handful of common methods, like
set
,get
,… more | homepage - component-emitter: Event emitter | homepage
- emitter-only: Extend event emitters to allow registering listeners only once. | homepage
Running tests
Install dev dependencies:
$ npm i -d && npm test
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Author
Brian Woodward
License
Copyright © 2015 Brian Woodward Released under the MIT license.
This file was generated by verb-cli on November 03, 2015.