1.1.0 • Published 8 years ago

microevent2 v1.1.0

Weekly downloads
16
License
MIT
Repository
github
Last release
8 years ago

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

1.1.0

8 years ago

1.0.13

8 years ago

1.0.12

8 years ago

1.0.11

8 years ago

1.0.10

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago