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

mitt

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mitt - npm Package Compare versions

Comparing version 2.0.1 to 2.1.0

index.d.ts

2

dist/mitt.es.js

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

export default function(n){return n=n||new Map,{on:function(t,e){var i=n.get(t);i&&i.push(e)||n.set(t,[e])},off:function(t,e){var i=n.get(t);i&&i.splice(i.indexOf(e)>>>0,1)},emit:function(t,e){(n.get(t)||[]).slice().map(function(n){n(e)}),(n.get("*")||[]).slice().map(function(n){n(t,e)})}}}
export default function(n){return{all:n=n||new Map,on:function(t,e){var i=n.get(t);i&&i.push(e)||n.set(t,[e])},off:function(t,e){var i=n.get(t);i&&i.splice(i.indexOf(e)>>>0,1)},emit:function(t,e){(n.get(t)||[]).slice().map(function(n){n(e)}),(n.get("*")||[]).slice().map(function(n){n(t,e)})}}}
//# sourceMappingURL=mitt.es.js.map

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

module.exports=function(n){return n=n||new Map,{on:function(e,t){var i=n.get(e);i&&i.push(t)||n.set(e,[t])},off:function(e,t){var i=n.get(e);i&&i.splice(i.indexOf(t)>>>0,1)},emit:function(e,t){(n.get(e)||[]).slice().map(function(n){n(t)}),(n.get("*")||[]).slice().map(function(n){n(e,t)})}}};
module.exports=function(n){return{all:n=n||new Map,on:function(e,t){var i=n.get(e);i&&i.push(t)||n.set(e,[t])},off:function(e,t){var i=n.get(e);i&&i.splice(i.indexOf(t)>>>0,1)},emit:function(e,t){(n.get(e)||[]).slice().map(function(n){n(t)}),(n.get("*")||[]).slice().map(function(n){n(e,t)})}}};
//# sourceMappingURL=mitt.js.map

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

export default function(e){return e=e||new Map,{on(t,n){const s=e.get(t);s&&s.push(n)||e.set(t,[n])},off(t,n){const s=e.get(t);s&&s.splice(s.indexOf(n)>>>0,1)},emit(t,n){(e.get(t)||[]).slice().map(e=>{e(n)}),(e.get("*")||[]).slice().map(e=>{e(t,n)})}}}
export default function(e){return{all:e=e||new Map,on(t,n){const s=e.get(t);s&&s.push(n)||e.set(t,[n])},off(t,n){const s=e.get(t);s&&s.splice(s.indexOf(n)>>>0,1)},emit(t,n){(e.get(t)||[]).slice().map(e=>{e(n)}),(e.get("*")||[]).slice().map(e=>{e(t,n)})}}}
//# sourceMappingURL=mitt.modern.js.map

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

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).mitt=n()}(this,function(){return function(e){return e=e||new Map,{on:function(n,t){var f=e.get(n);f&&f.push(t)||e.set(n,[t])},off:function(n,t){var f=e.get(n);f&&f.splice(f.indexOf(t)>>>0,1)},emit:function(n,t){(e.get(n)||[]).slice().map(function(e){e(t)}),(e.get("*")||[]).slice().map(function(e){e(n,t)})}}}});
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).mitt=n()}(this,function(){return function(e){return{all:e=e||new Map,on:function(n,t){var f=e.get(n);f&&f.push(t)||e.set(n,[t])},off:function(n,t){var f=e.get(n);f&&f.splice(f.indexOf(t)>>>0,1)},emit:function(n,t){(e.get(n)||[]).slice().map(function(e){e(t)}),(e.get("*")||[]).slice().map(function(e){e(n,t)})}}}});
//# sourceMappingURL=mitt.umd.js.map
{
"name": "mitt",
"version": "2.0.1",
"version": "2.1.0",
"description": "Tiny 200b functional Event Emitter / pubsub.",

@@ -11,8 +11,9 @@ "jsnext:main": "dist/mitt.es.js",

"umd:main": "dist/mitt.umd.js",
"typings": "dist/index.d.ts",
"typings": "index.d.ts",
"scripts": {
"test": "npm-run-all --silent typecheck lint testonly",
"testonly": "mocha --require esm test/**/*.js",
"test": "npm-run-all --silent typecheck lint mocha test-types",
"mocha": "mocha test",
"test-types": "tsc test/test-types-compilation.ts --noEmit",
"lint": "eslint src test --ext ts --ext js",
"typecheck": "tsc **/*.ts --noEmit",
"typecheck": "tsc --noEmit",
"bundle": "microbundle",

@@ -22,3 +23,3 @@ "build": "npm-run-all --silent clean -p bundle -s docs",

"docs": "documentation readme src/index.ts --section API -q --parse-extension ts",
"release": "npm run -s build -s && npm t && git commit -m $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish"
"release": "npm run -s build -s && npm t && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish"
},

@@ -39,4 +40,17 @@ "repository": "developit/mitt",

"src",
"dist"
"dist",
"index.d.ts"
],
"mocha": {
"extension": [
"ts"
],
"require": [
"ts-node/register",
"esm"
],
"spec": [
"test/*_test.ts"
]
},
"eslintConfig": {

@@ -74,3 +88,4 @@ "extends": [

"eslintIgnore": [
"dist"
"dist",
"index.d.ts"
],

@@ -89,4 +104,4 @@ "devDependencies": {

"esm": "^3.2.25",
"microbundle": "^0.12.0",
"mocha": "^7.2.0",
"microbundle": "^0.12.3",
"mocha": "^8.0.1",
"npm-run-all": "^4.1.5",

@@ -96,5 +111,5 @@ "rimraf": "^3.0.2",

"sinon-chai": "^3.5.0",
"ts-node": "^8.10.1",
"ts-node": "^8.10.2",
"typescript": "^3.9.3"
}
}
}

@@ -72,2 +72,5 @@ <p align="center">

// clearing all events
emitter.all.clear()
// working with handler references:

@@ -103,2 +106,3 @@ function onFoo() {}

- [mitt](#mitt)
- [all](#all)
- [on](#on)

@@ -117,2 +121,6 @@ - [Parameters](#parameters)

### all
A Map of event names to registered handler functions.
### on

@@ -119,0 +127,0 @@

@@ -5,4 +5,4 @@ export type EventType = string | symbol;

// and should not return a value
export type Handler = (event?: any) => void;
export type WildcardHandler= (type: EventType, event?: any) => void
export type Handler<T = any> = (event?: T) => void;
export type WildcardHandler = (type: EventType, event?: any) => void;

@@ -17,6 +17,8 @@ // An array of all currently registered event handlers for a type

export interface Emitter {
on(type: EventType, handler: Handler): void;
all: EventHandlerMap;
on<T = any>(type: EventType, handler: Handler<T>): void;
on(type: '*', handler: WildcardHandler): void;
off(type: EventType, handler: Handler): void;
off<T = any>(type: EventType, handler: Handler<T>): void;
off(type: '*', handler: WildcardHandler): void;

@@ -28,5 +30,6 @@

/** Mitt: Tiny (~200b) functional event emitter / pubsub.
* @name mitt
* @returns {Mitt}
/**
* Mitt: Tiny (~200b) functional event emitter / pubsub.
* @name mitt
* @returns {Mitt}
*/

@@ -39,2 +42,7 @@ export default function mitt(all?: EventHandlerMap): Emitter {

/**
* A Map of event names to registered handler functions.
*/
all,
/**
* Register an event handler for the given type.

@@ -45,3 +53,3 @@ * @param {string|symbol} type Type of event to listen for, or `"*"` for all events

*/
on(type: EventType, handler: Handler) {
on<T = any>(type: EventType, handler: Handler<T>) {
const handlers = all.get(type);

@@ -56,3 +64,2 @@ const added = handlers && handlers.push(handler);

* Remove an event handler for the given type.
*
* @param {string|symbol} type Type of event to unregister `handler` from, or `"*"`

@@ -62,3 +69,3 @@ * @param {Function} handler Handler function to remove

*/
off(type: EventType, handler: Handler) {
off<T = any>(type: EventType, handler: Handler<T>) {
const handlers = all.get(type);

@@ -80,3 +87,3 @@ if (handlers) {

*/
emit(type: EventType, evt: any) {
emit<T = any>(type: EventType, evt: T) {
((all.get(type) || []) as EventHandlerList).slice().map((handler) => { handler(evt); });

@@ -83,0 +90,0 @@ ((all.get('*') || []) as WildCardEventHandlerList).slice().map((handler) => { handler(type, evt); });

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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