1.0.1 • Published 6 years ago

jean-event-dispatcher v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Description

Provides functionality for an event-based communication system

Support

Supports both CommonJS and AMD eco system. If there is no loader, EventDispatcher is registered as a browser variable.

Code Example

  • Use it as browser variable
// Register functions for "event1"
EventDispatcher.subscribeEvent("event1", function (param) {
    // Work with param
});
EventDispatcher.subscribeEvent("event1", function (param) {
    // Work with param
});
//Publish parameters for "event1"
EventDispatcher.publishEvent("event1", { id: "123" });
  • Use it with require.js
require(["path/to/EventDispatcher"], function(EventDispatcher){
    // Work with EventDispatcher
});
  • Use it with node.js
var EventDispatcher = require("jean-event-dispatcher");

Installation

npm install jean-event-dispatcher --save --legacy-bundling

API Reference

EventDispatcher.subscribeEvent(name, fn)

Subscribes to an event

Parameters

  • name: String - Name of the event
  • fn: function - Function which will be notified, if the event fires

Returns

  • Boolean - True if subscription is successful, false otherwise

EventDispatcher.unsubscribeEvent(name, fn)

Unsubscribes from an event

Parameters

  • name: String - Name of the event
  • fn: function - Function which will be unsubscribed

Returns

  • Boolean - True if unsubscription is successful, false otherwise

EventDispatcher.publishEvent(name, params)

Publish to all event subscribers

Parameters

  • name: String - Name of the event which will be published
  • params: Any - Params to be published to all subscribers

Returns

  • Boolean - True if parameters are published, false otherwise

Tests

  • Open spec/spec-runner.html in browser to see the test cases.

License

MIT

1.0.1

6 years ago

1.0.0

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago