New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

seng-event

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

seng-event

Provides Classes and utilities for dispatching and listening to events.

  • 2.0.0-alpha.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.4K
increased by69.59%
Maintainers
1
Weekly downloads
 
Created
Source

Travis Code Climate Coveralls npm npm

seng-event

Provides Classes and utilities for dispatching and listening to events.

Provides an EventDispatcher base class that adds the ability to dispatch events and attach handlers that should be called when such events are triggered. New event classes can be created by extending the AbstractEvent class provided in this module. This module also provides basic event classes BasicEvent and CommonEvent that are ready to be used with EventDispatcher.

seng-event also supports event capturing and bubbling phases, heavily inspired by existing event dispatching systems like the functionality described in the DOM Event W3 spec

Installation

yarn add seng-event
npm i -S seng-event

Basic usage

import EventDispatcher, {AbstractEvent} from 'seng-event';
import {generateEventTypes, EVENT_TYPE_PLACEHOLDER} from 'seng-event/lib/util/eventTypeUtils';

// extend EventDispatcher
class Foo extends EventDispatcher {
  ...
}

// Create your own event class
class FooEvent extends AbstractEvent {
   ...
   public static COMPLETE:string = EVENT_TYPE_PLACEHOLDER;
   ...
}
generateEventTypes({FooEvent});

// listener for events
const foo = new Foo();
const exampleHandler = (event:FooEvent) => 
{
  console.log('Handler called!', event.type, event.target);
}
foo.addEventListener(FooEvent.COMPLETE, exampleHandler);

// dispatch an event (will execute exampleHandler and log 'Handler called!')
foo.dispatchEvent(new FooEvent(FooEvent.COMPLETE));  

Documentation

View the generated documentation.

Building

In order to build seng-event, ensure that you have Git and Node.js installed.

Clone a copy of the repo:

git clone https://github.com/mediamonks/seng-event.git

Change to the seng-event directory:

cd seng-event

Install dev dependencies:

yarn

Use one of the following main scripts:

yarn build            # build this project
yarn dev              # run compilers in watch mode, both for babel and typescript
yarn test             # run the unit tests incl coverage
yarn test:dev         # run the unit tests in watch mode
yarn lint             # run eslint and tslint on this project
yarn doc              # generate typedoc documentation

When installing this module, it adds a pre-commit hook, that runs lint and prettier commands before committing, so you can be sure that everything checks out.

Contribute

View CONTRIBUTING.md

Changelog

View CHANGELOG.md

Authors

View AUTHORS.md

LICENSE

MIT © MediaMonks

Keywords

FAQs

Package last updated on 22 Feb 2019

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc