Socket
Socket
Sign inDemoInstall

microevent2

Package Overview
Dependencies
0
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    microevent2

Event emitter tiny library


Version published
Maintainers
1
Created

Readme

Source

microevent2.js

microevent2.js is a event emitter library which provides the [observer pattern](http: //en.wikipedia.org/wiki/Observer_pattern) to javascript objects.

It works on ES6, node.js and browser. It is a single.js file containing

< a href = "https://raw.githubusercontent.com/sun2rise/microevent2/master/dist/microevent2.js" >

Usage

You need a single file microevent2.js. Include it in a webpage via the usual script tag.

<script src="microevent2.js"> </script>
var microevent2 = new MicroEvent2();

microevent2.on('some-event', someCallback);
microevent2.emit('some-event');

or

import MicroEvent2 from 'MicroEvent2';
let Object = function () {
  MicroEvent2.mixin(this);
  this.emit('ev.name', data);
}

or

var Microevent2 = require('microevent2')

Instance Methods

on(event, callback)

Subscribe to an event

  • event - the name of the event to subscribe to
  • callback - the function to call when event is emitted

once(event, callback[, context])

Subscribe to an event only once

  • event - the name of the event to subscribe to
  • callback - the function to call when event is emitted

off(event[, callback])

Unsubscribe from an event or all events.

  • event - the name of the event to unsubscribe from
  • callback - the function used when binding to the event

emit(event[, arguments...])

Trigger a named event

  • event - the event name to emit
  • arguments... - any number of arguments to pass to the event subscribers

pipe(eventEmitter)

Push events downstream from the handler to another

  • eventEmitter - the event emitter to pipe (to emit to)

unpipe(eventEmitter)

Unpipe events to the previously piped event emitter

  • eventEmitter - the event emitter to unpipe

mixin(destObject)

Mixin will delegate all microevent2 function in the destination object

  • destObject - the object which will support microevent2

bind

For compatibility, see on

unbind

For compatibility, see off

trigger

For compatibility, see emit

Example

see inside test folder

FAQs

Last updated on 04 Jul 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc