Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

emitit

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

emitit

Browser event emitter the node way.

  • 0.2.0-beta
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

emitit

For when you just want to listen to decent events and then do something...

Technical Overview

Emitit is abstraction on top of the DOMs native event-API. This feels to be necessary, because of weird-ish DOM-behaviour (Opinion). What you want to is to abstract events, listen for them and then act on them and specific data, not whole DOM-objects. Also this module guides the user gently to bind events as low as possible for performance reasons. While we are at it we can add CSS on a per node basis, forcibly preventing defaults, such as user-select.

For convenience the module can be called in a script tag without requiring or including it explicitly. This works after including the JS-file in the header of the HTML-document. This is because the node-style JS is build with browserify and attached to the global window object.

Pass in options into the constructor and be ready to listen to events.

Usage

npm install emitit
# and require it in your own browserify build

or

<!DOCTYPE html>
<html>
<head>
  <script src="../dist/emitter.min.js" charset="utf-8"></script>
</head>
<body>
    <div class="container">
     <div class="emitter boxes">
       <div class="emitter square over">over</div>
       <div class="emitter square click">click</div>
     </div>
   </div>

   <script type="text/javascript">

     // bind all target boxes through css electors
     var opts = {
       targets: [
         //  '.emitter.square', // proof that dupes will be filtered
         '.emitter.square.over',
         '.emitter.square.click'
       ],
       eventNames: ['click'], //required, no default fallback
       emitMessage: 'hello',
       //  deffered: false, // speed deferrance default: false
       queryRoot: document.body,
       //  allowDupes: false,
       //  allowToggle: true,
       preventDefaults: [
         { property:'user-select', value: 'none'}
       ],
       //  map: [
       //    {mapTarget: '.emitter.square.up', eventName: 'mouseup'},
       //    {mapTarget: '.emitter.square.down', eventName: 'mousedown'}
       //  ]
     }

     var emitter = new Emitter(opts);

     emitter.on('hello', function() {
       console.log('hello from emitter 1');
     })

     emitter.on('error', function() {
       console.log(err);
     })

     emitter.emit('hello')
   </script>
</body>
</html>

TODOs

  1. Test-suite
  2. CI-builds

Keywords

FAQs

Package last updated on 27 Jun 2015

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