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

emoney

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

emoney - npm Package Compare versions

Comparing version 0.2.4 to 1.0.0

.travis.yml

9

bower.json
{
"name": "emoney",
"version": "0.2.4",
"homepage": "https://github.com/elnarddogg/emoney.git",
"version": "1.0.0",
"homepage": "https://github.com/elnarddogg/emoney",
"authors": [

@@ -9,3 +9,3 @@ "Bernard McManus"

"description": "A lightweight event emitter for clients and servers",
"main": "dist/emoney-0.2.4.min.js",
"main": "dist/emoney.js",
"keywords": [

@@ -23,5 +23,4 @@ "javascript",

"bower_components",
"test",
"tests"
"test"
]
}

@@ -1,333 +0,220 @@

module.exports = function( grunt ) {
module.exports = function( grunt ){
// always print a stack trace if something goes wrong
grunt.option( 'stack' , true );
var fs = require( 'fs-extra' );
var cp = require( 'child_process' );
var util = require( 'util' );
var colors = require( 'colors' );
var Promise = require( 'es6-promise' ).Promise;
var AMDFormatter = require( 'es6-module-transpiler-amd-formatter' );
var transpiler = require( 'es6-module-transpiler' );
var Container = transpiler.Container;
var FileResolver = transpiler.FileResolver;
var BundleFormatter = transpiler.formatters.bundle;
var SRC = 'src/**/*.js';
grunt.initConfig({
pkg: grunt.file.readJSON( 'package.json' ),
'git-describe': {
'options': {
prop: 'git-version'
},
dist: {}
gitinfo: {},
clean: {
'dist': [ 'dist' ],
'compiled': [ 'compiled' ],
'test': [ 'test/*.compiled.js*' ]
},
jshint: {
all: [ 'Gruntfile.js' , SRC ],
all: 'src/**/*.js',
options: { esnext: true }
},
'import-clean': {
all: 'src/**/*.js'
},
update_json: {
options: {
esnext: true
src: 'package.json',
indent: 2
},
bower: {
dest: 'bower.json',
fields: [
'name',
'version',
'main',
'description',
'keywords',
'homepage',
'license'
]
}
},
'import-clean': {
all: SRC
browserify: {
options: {
transform: [
[ 'babelify' , { presets: [ 'es2015' ]}]
],
plugin: [
[ 'browserify-derequire' ]
],
browserifyOptions: {
'paths': [ 'src' ],
'debug': 'debug',
'standalone': 'E$'
}
},
compiled: {
files: {
'compiled/<%= pkg.name %>.js': 'src/index.js'
}
},
test: {
files: {
'test/imports.compiled.js': 'test/imports.js'
}
}
},
wrap: {
options: {
args: (function(){
var args = [
['$global','this'],
'Array',
'Object',
'Date',
'Error',
['UNDEFINED']
];
clean: {
'dist': [ 'dist' ],
'tmp': [ 'tmp' ],
'test': [ 'test/<%= pkg.name %>.js' , 'test/testModules.transpiled.js' ],
'common-dev': [ 'dist/<%= pkg.name %>-<%= pkg.version %>.js' ],
'common-prod': [ 'dist/<%= pkg.name %>-<%= pkg.version %>.min.js' ],
'amd-dev': [ 'dist/<%= pkg.name %>-<%= pkg.version %>.amd.js' ],
'amd-prod': [ 'dist/<%= pkg.name %>-<%= pkg.version %>.amd.min.js' ]
},
var leadingWrapArgs = args.map(function( arg ){
return Array.isArray( arg ) ? arg.shift() : arg;
})
.filter(function( arg ){
return !!arg;
});
replace: [{
options: {
patterns: [
{
match: /(\"version\")(.*?)(\")(.{1,}?)(\")/i,
replacement: '\"version\": \"<%= pkg.version %>\"'
},
{
match: /(\"main\")(.*?)(\")(.{1,}?)(\")/i,
replacement: '\"main\": \"dist/<%= pkg.name %>-<%= pkg.version %>.min.js\"'
}
var trailingWrapArgs = args.map(function( arg ){
return Array.isArray( arg ) ? arg.pop() : arg;
})
.filter(function( arg ){
return !!arg;
});
return {
leading: leadingWrapArgs,
trailing: trailingWrapArgs
};
}()),
wrapper: [
'(function(<%= wrap.options.args.leading %>){\n"use strict";\n',
'\n}(<%= wrap.options.args.trailing %>))'
]
},
files: [
{
src: 'package.json',
dest: 'package.json'
},
{
src: 'bower.json',
dest: 'bower.json'
compiled: {
files: {
'compiled/<%= pkg.name %>.js': 'compiled/<%= pkg.name %>.js'
}
]
}],
watch: {
debug: {
files: [ 'Gruntfile.js' , SRC , 'build/*.js' , 'test/*.js' ],
tasks: [ 'test' ]
},
test: {
files: {
'test/imports.compiled.js': 'test/imports.compiled.js'
}
}
},
transpile: {
amd: {
type: 'amd',
files: [{
expand: true,
cwd: 'src/',
src: [ '**/*.js' ],
dest: 'tmp/',
ext: '.amd.js'
}]
exorcise: {
compiled: {
files: {
'compiled/<%= pkg.name %>.js.map': 'compiled/<%= pkg.name %>.js'
}
},
test: {
files: {
'test/imports.compiled.js.map': 'test/imports.compiled.js'
}
}
},
concat: {
options: {
banner: '/*! <%= pkg.name %> - <%= pkg.version %> - <%= pkg.author.name %> - <%= grunt.config.get( \'git-branch\' ) %> - <%= grunt.config.get( \'git-hash\' ) %> - <%= grunt.template.today("yyyy-mm-dd") %> */\n\n'
banner: '<%= pkg.config.banner %>\n'
},
amd: {
src: 'tmp/**/*.amd.js',
dest: 'dist/<%= pkg.name %>-<%= pkg.version %>.amd.js'
},
common: {
src: 'tmp/<%= pkg.name %>.common.js',
dest: 'dist/<%= pkg.name %>-<%= pkg.version %>.js'
compiled: {
files: {
'compiled/<%= pkg.name %>.js': 'compiled/<%= pkg.name %>.js'
}
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> - <%= pkg.version %> - <%= pkg.author.name %> - <%= grunt.config.get( \'git-branch\' ) %> - <%= grunt.config.get( \'git-hash\' ) %> - <%= grunt.template.today("yyyy-mm-dd") %> */\n'
banner: '<%= pkg.config.banner %>'
},
amd: {
compiled: {
files: {
'dist/<%= pkg.name %>-<%= pkg.version %>.amd.min.js': 'tmp/**/*.amd.js'
'compiled/<%= pkg.name %>.min.js': 'compiled/<%= pkg.name %>.js'
}
},
common: {
}
},
mochaTest: {
dist: { src: 'test' }
},
copy: {
dist: {
files: [{
expand: true,
src: '*',
dest: 'dist/',
cwd: 'compiled/'
}]
}
},
watch: {
options: { interrupt: true },
debug: {
files: [ 'src/**/*.js' , 'test/!(*.compiled).js' ],
tasks: [ 'test' ]
}
},
'release-describe': {
dist: {
files: {
'dist/<%= pkg.name %>-<%= pkg.version %>.min.js': 'tmp/**/*.js'
'dist/<%= pkg.name %>.min.js': 'dist/<%= pkg.name %>.js'
}
}
}
},
});
grunt.loadTasks( 'tasks' );
[
'grunt-contrib-jshint',
'grunt-contrib-clean',
'grunt-git-describe',
'grunt-replace',
'grunt-contrib-concat',
'grunt-contrib-uglify',
'grunt-contrib-watch',
'grunt-es6-module-transpiler',
'grunt-import-clean'
'grunt-import-clean',
'grunt-update-json',
'grunt-browserify',
'grunt-gitinfo',
'grunt-contrib-copy',
'grunt-mocha-test',
'grunt-exorcise',
'grunt-wrap'
]
.forEach( grunt.loadNpmTasks );
function transpile( umd , out , formatter ) {
formatter = formatter || BundleFormatter;
var container = new Container({
resolvers: [new FileResolver([ 'src/' ])],
formatter: new formatter()
});
container.getModule( umd );
container.write( out );
// remove sourceMappingURL
var sourceMapRegex = /(^.*sourceMappingURL.*\n?$)/mi;
var transpiled = fs.readFileSync( out , 'utf-8' ).replace( sourceMapRegex , '' );
fs.writeFileSync( out , transpiled );
}
grunt.registerTask( 'transpile:testModules' , function() {
transpile( '../test/testModules' , 'test/testModules.transpiled.js' );
fs.removeSync( 'test/testModules.transpiled.js.map' );
});
grunt.registerTask( 'transpile:common' , function() {
var name = grunt.config.get( 'pkg.name' );
transpile( '../build/' + name + '.umd' , 'tmp/' + name + '.common.js' );
});
grunt.registerTask( 'git-hash' , function() {
grunt.task.requires( 'git-describe' );
var rev = grunt.config.get( 'git-version' );
var matches = rev.match( /\-?([A-Za-z0-9]{7})\-?/ );
var hash = matches
.filter(function( match ) {
return match.length === 7;
})
.pop();
if (matches && matches.length > 1) {
grunt.config.set( 'git-hash' , hash );
}
else{
grunt.config.set( 'git-hash' , rev );
}
});
grunt.registerTask( 'git-branch' , function() {
var done = this.async();
cp.exec( 'git status' , function( err , stdout , stderr ) {
if (!err) {
var branch = stdout
.split( '\n' )
.shift()
.replace( /on\sbranch\s/i , '' );
grunt.config.set( 'git-branch' , branch );
}
done();
});
});
grunt.registerTask( 'build:describe-prod' , function() {
var files = grunt.file.expand( SRC );
var pkg = grunt.config.get( 'pkg' );
var name = pkg.name + '-' + pkg.version + '.min.js';
var bytesInit = files.reduce(function( prev , current ) {
return prev + fs.statSync( current ).size;
}, 0);
var bytesFinal = fs.statSync( 'dist/' + name ).size;
var kbInit = (Math.round( bytesInit / 10 ) / 100);
var kbFinal = (Math.round( bytesFinal / 10 ) / 100).toString();
console.log('File ' + name.cyan + ' created: ' + (kbInit + ' kB').green + ' \u2192 ' + (kbFinal + ' kB').green);
});
grunt.registerTask( 'copyTestBuild' , function() {
var version = grunt.config.get( 'pkg.version' );
var name = grunt.config.get( 'pkg.name' );
var src = 'dist/' + name + '-' + version + '.js';
var dest = 'test/' + name + '.js';
fs.copySync( src , dest );
});
grunt.registerTask( 'runTests' , function() {
var done = this.async();
new Promise(function( resolve ) {
var task = cp.spawn( 'npm' , [ 'test' ]);
resolve( task.stdout );
})
.then(function( readable ) {
readable.pipe( process.stdout );
return new Promise(function( resolve , reject ) {
readable.on( 'end' , resolve );
readable.on( 'error' , reject );
})
.catch(function( err ) {
return err;
});
})
.then( done );
});
grunt.registerTask( 'git' , [
'git-describe',
'git-hash',
'git-branch'
]);
grunt.registerTask( 'default' , [
'clean',
'build',
'replace',
'test',
'clean:test',
'build:describe-prod'
'uglify',
'copy:dist',
'update_json',
'release-describe'
]);
grunt.registerTask( 'build' , [
'git',
'clean:dist',
//'build:amd',
'build:common'
]);
grunt.registerTask( 'build:common' , [
'build:common-dev',
'build:common-prod'
]);
grunt.registerTask( 'build:common-prod' , [
'clean:common-prod',
'transpile:common',
'uglify:common',
'clean:tmp'
]);
grunt.registerTask( 'build:common-dev' , [
'clean:common-dev',
'transpile:common',
'concat:common',
'clean:tmp'
]);
grunt.registerTask( 'build:amd' , [
'build:amd-dev',
'build:amd-prod'
]);
grunt.registerTask( 'build:amd-prod' , [
'clean:amd-prod',
'transpile:amd',
'uglify:amd',
'clean:tmp'
]);
grunt.registerTask( 'build:amd-dev' , [
'clean:amd-dev',
'transpile:amd',
'concat:amd',
'clean:tmp'
]);
grunt.registerTask( 'test' , [
'jshint',
'import-clean',
'clean:test',
'build:common-dev',
'copyTestBuild',
'transpile:testModules',
'runTests'
'gitinfo',
'browserify',
'wrap',
'exorcise',
'concat'
]);
grunt.registerTask( 'test' , function(){
try {
grunt.task.requires( 'build' );
}
catch( err ){
grunt.task.run( 'build' );
}
grunt.task.run( 'mochaTest' );
});

@@ -338,20 +225,2 @@ grunt.registerTask( 'debug' , [

]);
};

@@ -1,2 +0,2 @@

Copyright (c) 2014 Bernard McManus
Copyright (c) 2016 Bernard McManus

@@ -3,0 +3,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of

{
"name": "emoney",
"version": "0.2.4",
"version": "1.0.0",
"description": "A lightweight event emitter for clients and servers",
"main": "dist/emoney-0.2.4.min.js",
"main": "dist/emoney.js",
"scripts": {
"test": "mocha test/test.js"
"install": "bower install",
"test": "grunt test",
"build": "grunt"
},
"config": {
"banner": "/*! <%= pkg.name %> - <%= pkg.version %> - <%= pkg.author.name %> - <%= grunt.config.data.gitinfo.local.branch.current.shortSHA %> - <%= grunt.template.today('yyyy-mm-dd') %> */\n"
},
"devDependencies": {
"es6-module-transpiler": ">=0.9.0",
"mocha": "~1.21.4",
"chai": ">=1.9.1",
"fs-extra": ">=0.9.1",
"colors": "~1.0.3",
"es6-promise": "~2.0.1",
"grunt": "~0.4.2",
"grunt-contrib-jshint": "~0.6.3",
"grunt-contrib-concat": ">=0.4.0",
"grunt-contrib-uglify": ">=0.2.2",
"grunt-contrib-clean": ">=0.4.1",
"grunt-replace": ">=0.7.7",
"grunt-git-describe": "~2.0.2",
"grunt-contrib-watch": ">=0.6.1",
"grunt-import-clean": ">=0.1.0",
"grunt-jsdoc": ">=0.5.7",
"es6-module-transpiler-amd-formatter": ">=0.0.1",
"grunt-es6-module-transpiler": ">=0.6.0"
"babel-preset-es2015": "^6.3.13",
"babelify": "^7.2.0",
"bower": "^1.7.1",
"browserify-derequire": "^0.9.4",
"chai": "^3.4.1",
"colors": "^1.0.3",
"es6-promise": "^2.0.1",
"fs-extra": "^0.26.3",
"grunt": "^0.4.2",
"grunt-browserify": "^4.0.1",
"grunt-cli": "^0.1.13",
"grunt-contrib-clean": "^0.4.1",
"grunt-contrib-concat": "^0.4.0",
"grunt-contrib-copy": "^0.8.2",
"grunt-contrib-jshint": "^0.11.3",
"grunt-contrib-uglify": "^0.2.2",
"grunt-contrib-watch": "^0.6.1",
"grunt-exorcise": "^2.1.0",
"grunt-gitinfo": "^0.1.7",
"grunt-import-clean": "^0.1.0",
"grunt-mocha-test": "^0.12.7",
"grunt-update-json": "^0.2.1",
"grunt-wrap": "^0.3.0",
"mocha": "^2.3.4"
},

@@ -45,6 +56,3 @@ "repository": {

},
"license": {
"type": "MIT",
"url": "https://github.com/elnarddogg/emoney/blob/master/LICENSE.txt"
},
"license": "MIT",
"bugs": {

@@ -51,0 +59,0 @@ "url": "https://github.com/elnarddogg/emoney/issues"

E$
==
> A lightweight event emitter for clients and servers.
[![travis-ci](https://travis-ci.org/elnarddogg/emoney.svg)](https://travis-ci.org/elnarddogg/emoney)
[![david-dm](https://david-dm.org/elnarddogg/emoney.svg)](https://david-dm.org/elnarddogg/emoney)
![npm](https://img.shields.io/npm/v/npm.svg)
![bower](https://img.shields.io/bower/v/bootstrap.svg)
Overview

@@ -12,19 +16,21 @@ --------

```javascript
var emoneyStandalone = E$({
handleE$: function( e ) { ... }
// Standalone
var emoney = E$({
handleE$: function(){ ... }
});
var emoneyExtended = (function() {
// ES5
function E$Extended(){
E$.call( this );
}
E$Extended.prototype = Object.create( E$.prototype );
E$Extended.prototype.handleE$ = function(){ ... };
function E$ishConstructor() {
E$.construct( this );
// ES6
class E$Extended {
constructor(){
super();
}
E$ishConstructor.prototype = E$.create({
handleE$: function( e ) { ... }
});
return new E$ishConstructor();
}());
handleE$(){ ... }
}
```

@@ -35,12 +41,12 @@

```javascript
emoneyExtended
.$when( 'loading' , function( e , pct ) {
console.log( 'loading... (' + pct + '%)' );
})
.$when( 'ready' , function( e ) {
console.log( 'ready!' );
})
.$when( 'error' , function( e , err ) {
console.error( err.stack );
});
emoney
.$when( 'loading' , function( e , pct ){
console.log( 'loading... (%s%)' , pct );
})
.$when( 'ready' , function(){
console.log( 'ready!' );
})
.$when( 'error' , function( e , err ){
console.error( err.stack );
});
```

@@ -51,46 +57,45 @@

```javascript
emoneyExtended.$watch( emoneyStandalone );
// when emoneyStandalone emits an event
emoneyStandalone.$emit( 'gnarly' , [ 'something' , { rad: true }]);
// emoneyExtended.handleE$ is executed with arguments:
// [ event , something , { rad: true }]
var watcher = E$({
handleE$: function( e , str , obj ){
expect( str ).to.eql( 'awesome' );
expect( obj ).to.eql({ rad: true });
}
});
watcher.$watch( emitter );
emitter.$emit( 'gnarly' , [ 'awesome' , { rad: true }]);
```
Methods
-------
> E$ can be used to create a DOM-like event tree.
### Static Methods
```javascript
var called = false;
#### E$.create( prototype )
watcher2
.$watch( watcher1 )
.$when( 'gnarly' , function( e ){
called = true;
});
> creates a new object that extends the E$ prototype.
watcher1
.$watch( emitter )
.$when( 'gnarly' , function( e ){
expect( e.target ).to.equal( emitter );
e.stopPropagation();
});
```javascript
E$ishConstructor.prototype = E$.create({
method1: function() { ... },
method2: function() { ... },
handleE$: function( e ) { ... }
emitter.$emit( 'gnarly' , function(){
expect( called ).to.be.false;
});
```
#### E$.construct( instance )
Methods
-------
> defines required properties for an E$ instance.
### _`(static)`_ E$.is( subject ) &#8594; _`{boolean}`_
```javascript
function E$ishConstructor() {
E$.construct( this );
// ...
}
```
> Returns true if subject is E$-ish, false otherwise.
#### E$.is( subject )
> determines whether subject is E$-ish.
```javascript
var emoney = E$({ gnarly: true });
var emoneyIsh = new E$ishConstructor();
var emoney = E$();
var emoneyIsh = new E$Extended();
var somethingElse = new SomethingElse();

@@ -107,82 +112,72 @@

### Public Methods
### .$when( events , args<sub>_opt_</sub> , handler<sub>_opt_</sub> ) &#8594; _`{instance}`_
> All public methods can be chained.
> Adds an event listener.
#### .$when( events , [ args ] , [ handler ])
> adds an event listener.
| Parameter | Type | Description | Required |
| --------- | ---- | ----------- | -------- |
| `events` | `String`<br>`Array` | The event(s) to be handled. | __yes__ |
| `args` | `Variant`<br>`Array` | The argument(s) to be bound to the event handler. | _no_ |
| `handler` | `Function`<br>`E$` | The event handler.<br>If `E$.is( handler ) == true`, the event will be bound to `instance.handleE$`.<br>If `handler` is falsy, the event will be bound to `emoney.handleE$`. | _no_ |
| `events` | `string`<br>`array` | The event(s) to be handled. | __yes__ |
| `args` | `variant`<br>`array` | The argument(s) to be bound to the event handler. | no |
| `handler` | `function`<br>`E$` | The event handler.<br>If `E$.is( handler ) == true`, the event will be bound to `instance.handleE$`.<br>If `handler` is falsy, the event will be bound to `emoney.handleE$`. | no |
```javascript
// basic use
emoney.$when( 'gnarly' , function( e ) { ... });
emoney.$when( 'gnarly' , function(){ ... });
// bind an argument to multiple events
emoney.$when([ 'gnarly' , 'rad' ] , 'arg' , function( e , arg ) { ... });
// bind multiple arguments to the wildcard event
emoney.$when( '*' , [ 'arg1' , 'arg2' ] , function( e , arg1 , arg2 ) { ... });
emoney.$when([ 'gnarly' , 'rad' ] , 'arg' , function(){ ... });
```
#### .$once( events , [ args ] , [ handler ])
### .$once( events , args<sub>_opt_</sub> , handler<sub>_opt_</sub> ) &#8594; _`{instance}`_
> adds an event listener that is removed after the first time it is invoked.
> Adds an event listener that is removed after the first time it is invoked.
| Parameter | Type | Description | Required |
| --------- | ---- | ----------- | -------- |
| `events` | `String`<br>`Array` | The event(s) to be handled. | __yes__ |
| `args` | `Variant`<br>`Array` | The argument(s) to be bound to the event handler. | _no_ |
| `handler` | `Function`<br>`E$` | the event handler | _no_ |
| `events` | `string`<br>`array` | The event(s) to be handled. | __yes__ |
| `args` | `variant`<br>`array` | The argument(s) to be bound to the event handler. | no |
| `handler` | `function`<br>`E$` | The event handler. | no |
```javascript
// basic use
emoney.$once( 'gnarly' , function( e ) { ... });
emoney.$once( 'gnarly' , function(){ ... });
// bind an argument to multiple events
emoney.$once([ 'gnarly' , 'rad' ] , 'arg' , function( e , arg ) { ... });
// bind multiple arguments to the wildcard event
emoney.$once( '*' , [ 'arg1' , 'arg2' ] , function( e , arg1 , arg2 ) { ... });
emoney.$once([ 'gnarly' , 'rad' ] , 'arg' , function(){ ... });
```
#### .$emit( events , [ args ] , [ callback ])
### .$emit( events , args<sub>_opt_</sub> , callback<sub>_opt_</sub> ) &#8594; _`{instance}`_
> emits an event.
> Emits an event.
| Parameter | Type | Description | Required |
| --------- | ---- | ----------- | -------- |
| `events` | `String`<br>`Array` | the event(s) to be emitted | __yes__ |
| `args` | `Variant`<br>`Array` | the argument(s) to be passed to the event handler | _no_ |
| `callback` | `Function` | a function to be executed at the end of the event chain (see [event behavior](#behavior)) | _no_ |
| `events` | `string`<br>`array` | The event(s) to be emitted. | __yes__ |
| `args` | `variant`<br>`array` | The argument(s) to be passed to the event handler. | no |
| `callback` | `function` | A function to be executed at the end of the event chain (see [event behavior](#behavior)). | no |
```javascript
// basic use
emoney.$emit( 'gnarly' , function( e ) { ... });
emoney.$emit( 'gnarly' , function(){ ... });
// pass an argument to multiple event handlers
emoney.$emit([ 'gnarly' , 'rad' ] , 'arg' , function( e ) { ... });
emoney.$emit([ 'gnarly' , 'rad' ] , 'arg' , function(){ ... });
// pass multiple arguments to an event handler
emoney.$emit( 'gnarly' , [ 'arg1' , 'arg2' ] , function( e ) { ... });
emoney.$emit( 'gnarly' , [ 'arg1' , 'arg2' ] , function(){ ... });
```
#### .$dispel( events , [ wildcard ] , [ handler ])
### .$dispel( events , wild<sub>_opt_</sub> , handler<sub>_opt_</sub> ) &#8594; _`{instance}`_
> removes an event listener.
> Removes an event listener.
| Parameter | Type | Description | Required |
| --------- | ---- | ----------- | -------- |
| `events` | `String`<br>`Array`<br>`null` | The event(s) to be removed. | __yes__ |
| `wildcard` | `Boolean` | A boolean value denoting whether handlers bound to the wildcard event should be removed. | _no_ |
| `handler` | `Function`<br>`E$` | the event handler | _no_ |
| `events` | `string`<br>`array`<br>`null` | The event(s) to be removed. | __yes__ |
| `wild` | `boolean` | A boolean value denoting whether handlers bound to the wildcard event should be removed. | no |
| `handler` | `function`<br>`E$` | The event handler. | no |
```javascript
// remove any gnarly listeners bound to handlerFunc
emoney.$dispel( 'gnarly' , handlerFunc );
// remove any gnarly listeners bound to handlerFn
emoney.$dispel( 'gnarly' , handlerFn );

@@ -192,7 +187,7 @@ // remove all gnarly or rad listeners bound to any handler

// remove all listeners bound to handlerFunc except wildcard listeners
emoney.$dispel( null , handlerFunc );
// remove all listeners bound to handlerFn except wildcard listeners
emoney.$dispel( null , handlerFn );
// remove all listeners bound to handlerFunc
emoney.$dispel( null , true , handlerFunc );
// remove all listeners bound to handlerFn
emoney.$dispel( null , true , handlerFn );

@@ -203,9 +198,9 @@ // remove all listeners

#### .$watch( emitters )
### .$watch( emitters ) &#8594; _`{instance}`_
> starts listening to an E$ instance. `emitter` events will be handled by `listener.handleE$`.
> Starts watching E$ instance(s).
| Parameter | Type | Description | Required |
| --------- | ---- | ----------- | -------- |
| `emitters` | `E$`<br>`Array` | The target E$ instance(s). | __yes__ |
| `emitters` | `E$`<br>`array` | The E$ instance(s) to watch. | __yes__ |

@@ -220,16 +215,16 @@ ```javascript

#### .$ignore( emitters )
### .$unwatch( emitters ) &#8594; _`{instance}`_
> stops listening to an E$ instance.
> Stops watching E$ instance(s).
| Parameter | Type | Description | Required |
| --------- | ---- | ----------- | -------- |
| `emitters` | `E$`<br>`Array` | The target E$ instance(s). | __yes__ |
| `emitters` | `E$`<br>`array` | The E$ instance(s) to stop watching. | __yes__ |
```javascript
// ignore a single emitter
listener.$ignore( emitter1 );
// stop watching a single emitter
listener.$unwatch( emitter1 );
// ignore multiple emitters
listener.$ignore([ emitter1 , emitter2 ]);
// stop watching multiple emitters
listener.$unwatch([ emitter1 , emitter2 ]);
```

@@ -244,7 +239,7 @@

| -------- | ---- | ------- | ----------- |
| `target` | `Object` | `n/a` | The event target. |
| `type` | `String` | `n/a` | The event type. |
| `defaultPrevented` | `Boolean` | `false` | A flag denoting whether default was prevented. |
| `cancelBubble` | `Boolean` | `false` | A flag denoting whether propagation was stopped. |
| `timeStamp` | `Float` | `n/a` | The time at which the event was first triggered. |
| `target` | `E$` | `n/a` | The event target. |
| `type` | `string` | `n/a` | The event type. |
| `defaultPrevented` | `boolean` | `false` | A flag denoting whether default was prevented. |
| `cancelBubble` | `boolean` | `false` | A flag denoting whether propagation was stopped. |
| `timeStamp` | `number` | `n/a` | The time at which the event was first triggered. |

@@ -255,21 +250,21 @@ ### Methods

> prevents the $emit callback from being executed.
> Prevents the $emit callback from being executed.
```javascript
emoney
.$when( 'gnarly' , function( e ) {
.$when( 'gnarly' , function( e ){
e.preventDefault();
console.log( 'handler1' );
})
.$when( 'gnarly' , function( e ) {
.$when( 'gnarly' , function(){
console.log( 'handler2' );
})
.$emit( 'gnarly' , function( e ) {
.$emit( 'gnarly' , function(){
console.log( 'callback' );
});
/*
** > 'handler1'
** > 'handler2'
*/
/**
* > 'handler1'
* > 'handler2'
*/
```

@@ -279,21 +274,21 @@

> stops execution of the event chain and executes the emit callback.
> Stops execution of the event chain and executes the emit callback.
```javascript
emoney
.$when( 'gnarly' , function( e ) {
.$when( 'gnarly' , function( e ){
e.stopPropagation();
console.log( 'handler1' );
})
.$when( 'gnarly' , function( e ) {
.$when( 'gnarly' , function(){
console.log( 'handler2' );
})
.$emit( 'gnarly' , function( e ) {
.$emit( 'gnarly' , function(){
console.log( 'callback' );
});
/*
** > 'handler1'
** > 'callback'
*/
/**
* > 'handler1'
* > 'callback'
*/
```

@@ -311,20 +306,2 @@

> Build configs can be found in [Gruntfile.js](Gruntfile.js)
### default
> Builds dev and prod releases, then runs tests.
grunt
### test
> Builds dev release and then runs tests.
grunt test
### debug
> Builds dev release, runs tests, then watches source files for changes.
grunt debug
npm i && npm run build

@@ -1,47 +0,21 @@

import {
$CANCEL_BUBBLE,
$DEFAULT_PREVENTED,
$PROTO
} from 'static/constants';
import { $_uts } from 'static/shared';
import { WILDCARD } from 'listener-manager';
export default function Event( target , type ) {
export default function Event( target , type ){
if (type == WILDCARD) {
throw new Error( 'Invalid event type: ' + WILDCARD + '.' );
}
var that = this;
that.target = target;
that.type = type;
that[$CANCEL_BUBBLE] = false;
that[$DEFAULT_PREVENTED] = false;
that.timeStamp = $_uts();
that.cancelBubble = false;
that.defaultPrevented = false;
that.timeStamp = Date.now();
}
Event.prototype.preventDefault = function(){
this.defaultPrevented = true;
};
Event[$PROTO] = {
preventDefault: function() {
this[$DEFAULT_PREVENTED] = true;
},
stopPropagation: function() {
this[$CANCEL_BUBBLE] = true;
}
Event.prototype.stopPropagation = function(){
this.cancelBubble = true;
};

@@ -1,30 +0,111 @@

import { $_is } from 'static/shared';
import Event from 'event';
import {
WILDCARD,
default as ListenerManager
} from 'listener-manager';
import {
$_toArray,
$_isObject,
$_isFunction,
$_each
} from 'helpers';
import {
whenParser,
emitParser,
dispelParser
} from 'argument-parsers';
export default function E$( seed ) {
export default function E$( seed ){
var that = this;
if ($_is( that , E$ )) {
that.__init( that , ( seed || {} ));
}
else {
if (that == $global || that == UNDEFINED) {
return new E$( seed );
}
$_each( seed , function( value , key ){
that[key] = value;
});
var listeners = new ListenerManager(),
descriptors = {
$__listeners: { value: listeners },
$__handleWild: { value: function(){
var args = $_toArray( arguments ),
evt = args.shift();
listeners.invoke( evt , args );
}},
handleE$: {
value: (that.handleE$ || function(){}).bind( that )
},
};
$_each( descriptors , function( descriptor ){
descriptor.configurable = true;
});
Object.defineProperties( that , descriptors );
}
E$.is = function( subject ) {
return !!subject && $_isObject( subject ) && $_isFunction( subject.handleE$ );
};
E$.prototype = {
constructor: E$,
$watch: function( emitters ){
var that = this;
emitters = [].concat( emitters );
$_each( emitters , function( emitter , key ){
emitter
.$when( WILDCARD , that )
.$when( WILDCARD , that.$__handleWild );
});
return that;
},
$unwatch: function( emitters ){
var that = this;
emitters = [].concat( emitters );
$_each( emitters , function( emitter ){
emitter
.$dispel( WILDCARD , true , that )
.$dispel( WILDCARD , true , that.$__handleWild );
});
return that;
},
$once: function(){
var that = this,
called;
whenParser( that , arguments , function( eventTypes , listenerArgs , listenerFn ){
that.$when( eventTypes , listenerArgs , function once(){
if (!called) {
called = true;
listenerFn.apply( UNDEFINED , arguments );
that.$dispel( eventTypes , true , once );
}
});
});
return that;
},
$when: function(){
var that = this;
whenParser( that , arguments , function( eventTypes , listenerArgs , listenerFn ){
that.$__listeners.add( eventTypes , listenerFn , listenerArgs );
});
return that;
},
$emit: function(){
var that = this;
emitParser( that , arguments , function( eventTypes , listenerArgs , emitCb ){
$_each( eventTypes , function( type ){
var evt = new Event( that , type );
that.$__listeners.invoke( evt , listenerArgs );
if ($_isFunction( emitCb ) && !evt.defaultPrevented) {
emitCb.apply( UNDEFINED , [].concat( evt , listenerArgs ));
}
});
});
return that;
},
$dispel: function(){
var that = this;
dispelParser( that , arguments , function( eventTypes , wild , listenerFn ){
that.$__listeners.remove( eventTypes , listenerFn , wild );
});
return that;
}
};

Sorry, the diff of this file is not supported yet

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