前端代码
This commit is contained in:
26
node_modules/mitt/CHANGELOG.md
generated
vendored
Normal file
26
node_modules/mitt/CHANGELOG.md
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
# Change Log
|
||||
|
||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||
|
||||
<a name="1.2.1"></a>
|
||||
## [1.2.1](https://github.com/developit/mitt/compare/v1.1.3...v1.2.1) (2019-10-21)
|
||||
|
||||
|
||||
|
||||
<a name="1.1.3"></a>
|
||||
## [1.1.3](https://github.com/developit/mitt/compare/v1.1.2...v1.1.3) (2017-12-07)
|
||||
|
||||
|
||||
|
||||
<a name="1.1.2"></a>
|
||||
## [1.1.2](https://github.com/developit/mitt/compare/v1.1.1...v1.1.2) (2017-04-17)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **builds:** point `jsnext:main` to the ESM build instead of src, which contains things like Flowtype annotations that are not stripped by most build tools ([0cad092](https://github.com/developit/mitt/commit/0cad092))
|
||||
|
||||
|
||||
|
||||
<a name="1.1.1"></a>
|
||||
## [1.1.1](https://github.com/developit/mitt/compare/1.1.0...1.1.1) (2017-04-15)
|
168
node_modules/mitt/README.md
generated
vendored
Normal file
168
node_modules/mitt/README.md
generated
vendored
Normal file
@ -0,0 +1,168 @@
|
||||
<p align="center">
|
||||
<img src="https://i.imgur.com/BqsX9NT.png" width="300" height="300" alt="mitt">
|
||||
<br>
|
||||
<a href="https://www.npmjs.org/package/mitt"><img src="https://img.shields.io/npm/v/mitt.svg?style=flat" alt="npm"></a> <a href="https://travis-ci.org/developit/mitt"><img src="https://travis-ci.org/developit/mitt.svg?branch=master" alt="travis"></a> <a href="https://david-dm.org/developit/mitt"><img src="https://david-dm.org/developit/mitt/status.svg" alt="dependencies Status"></a> <a href="https://unpkg.com/mitt/dist/mitt.umd.js"><img src="http://img.badgesize.io/https://unpkg.com/mitt/dist/mitt.umd.js?compression=gzip" alt="gzip size"></a> <a href="https://packagephobia.now.sh/result?p=mitt"><img src="https://packagephobia.now.sh/badge?p=mitt" alt="install size"></a>
|
||||
|
||||
</p>
|
||||
|
||||
# Mitt
|
||||
|
||||
> Tiny 200b functional event emitter / pubsub.
|
||||
|
||||
- **Microscopic:** weighs less than 200 bytes gzipped
|
||||
- **Useful:** a wildcard `"*"` event type listens to all events
|
||||
- **Familiar:** same names & ideas as [Node's EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter)
|
||||
- **Functional:** methods don't rely on `this`
|
||||
- **Great Name:** somehow [mitt](https://npm.im/mitt) wasn't taken
|
||||
|
||||
Mitt was made for the browser, but works in any JavaScript runtime. It has no dependencies and supports IE9+.
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Install](#install)
|
||||
- [Usage](#usage)
|
||||
- [Examples & Demos](#examples--demos)
|
||||
- [API](#api)
|
||||
- [Contribute](#contribute)
|
||||
- [License](#license)
|
||||
|
||||
## Install
|
||||
|
||||
This project uses [node](http://nodejs.org) and [npm](https://npmjs.com). Go check them out if you don't have them locally installed.
|
||||
|
||||
```sh
|
||||
$ npm install --save mitt
|
||||
```
|
||||
|
||||
Then with a module bundler like [rollup](http://rollupjs.org/) or [webpack](https://webpack.js.org/), use as you would anything else:
|
||||
|
||||
```javascript
|
||||
// using ES6 modules
|
||||
import mitt from 'mitt'
|
||||
|
||||
// using CommonJS modules
|
||||
var mitt = require('mitt')
|
||||
```
|
||||
|
||||
The [UMD](https://github.com/umdjs/umd) build is also available on [unpkg](https://unpkg.com):
|
||||
|
||||
```html
|
||||
<script src="https://unpkg.com/mitt/dist/mitt.umd.js"></script>
|
||||
```
|
||||
|
||||
You can find the library on `window.mitt`.
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import mitt from 'mitt'
|
||||
|
||||
const emitter = mitt()
|
||||
|
||||
// listen to an event
|
||||
emitter.on('foo', e => console.log('foo', e) )
|
||||
|
||||
// listen to all events
|
||||
emitter.on('*', (type, e) => console.log(type, e) )
|
||||
|
||||
// fire an event
|
||||
emitter.emit('foo', { a: 'b' })
|
||||
|
||||
// working with handler references:
|
||||
function onFoo() {}
|
||||
emitter.on('foo', onFoo) // listen
|
||||
emitter.off('foo', onFoo) // unlisten
|
||||
```
|
||||
|
||||
### Typescript
|
||||
|
||||
```ts
|
||||
import mitt from 'mitt';
|
||||
const emitter: mitt.Emitter = mitt();
|
||||
```
|
||||
|
||||
## Examples & Demos
|
||||
|
||||
<a href="http://codepen.io/developit/pen/rjMEwW?editors=0110">
|
||||
<b>Preact + Mitt Codepen Demo</b>
|
||||
<br>
|
||||
<img src="https://i.imgur.com/CjBgOfJ.png" width="278" alt="preact + mitt preview">
|
||||
</a>
|
||||
|
||||
* * *
|
||||
|
||||
## API
|
||||
|
||||
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
||||
|
||||
### mitt
|
||||
|
||||
Mitt: Tiny (~200b) functional event emitter / pubsub.
|
||||
|
||||
**Parameters**
|
||||
|
||||
- `all` **EventHandlerMap**
|
||||
|
||||
Returns **Mitt**
|
||||
|
||||
### on
|
||||
|
||||
Register an event handler for the given type.
|
||||
|
||||
**Parameters**
|
||||
|
||||
- `type` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Type of event to listen for, or `"*"` for all events
|
||||
- `handler` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Function to call in response to given event
|
||||
|
||||
### off
|
||||
|
||||
Remove an event handler for the given type.
|
||||
|
||||
**Parameters**
|
||||
|
||||
- `type` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Type of event to unregister `handler` from, or `"*"`
|
||||
- `handler` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Handler function to remove
|
||||
|
||||
### emit
|
||||
|
||||
Invoke all handlers for the given type.
|
||||
If present, `"*"` handlers are invoked after type-matched handlers.
|
||||
|
||||
**Parameters**
|
||||
|
||||
- `type` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The event type to invoke
|
||||
- `evt` **Any?** Any value (object is recommended and powerful), passed to each handler
|
||||
|
||||
## Contribute
|
||||
|
||||
First off, thanks for taking the time to contribute!
|
||||
Now, take a moment to be sure your contributions make sense to everyone else.
|
||||
|
||||
Development Start:
|
||||
|
||||
This project is typed with Flow Type annotations. To ensure you have the proper typings for this project run
|
||||
|
||||
`flow-typed install`
|
||||
|
||||
### Reporting Issues
|
||||
|
||||
Found a problem? Want a new feature? First of all see if your issue or idea has [already been reported](../../issues).
|
||||
If don't, just open a [new clear and descriptive issue](../../issues/new).
|
||||
|
||||
### Submitting pull requests
|
||||
|
||||
Pull requests are the greatest contributions, so be sure they are focused in scope, and do avoid unrelated commits.
|
||||
|
||||
- Fork it!
|
||||
- Clone your fork: `git clone https://github.com/<your-username>/mitt`
|
||||
- Navigate to the newly cloned directory: `cd mitt`
|
||||
- Create a new branch for the new feature: `git checkout -b my-new-feature`
|
||||
- Install the tools necessary for development: `npm install`
|
||||
- Make your changes.
|
||||
- Commit your changes: `git commit -am 'Add some feature'`
|
||||
- Push to the branch: `git push origin my-new-feature`
|
||||
- Submit a pull request with full remarks documenting your changes.
|
||||
|
||||
## License
|
||||
|
||||
[MIT License](https://opensource.org/licenses/MIT) © [Jason Miller](https://jasonformat.com/)
|
64
node_modules/mitt/dist/mitt.es.js
generated
vendored
Normal file
64
node_modules/mitt/dist/mitt.es.js
generated
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
//
|
||||
// An event handler can take an optional event argument
|
||||
// and should not return a value
|
||||
|
||||
|
||||
|
||||
// An array of all currently registered event handlers for a type
|
||||
|
||||
|
||||
// A map of event types and their corresponding event handlers.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** Mitt: Tiny (~200b) functional event emitter / pubsub.
|
||||
* @name mitt
|
||||
* @returns {Mitt}
|
||||
*/
|
||||
function mitt(all ) {
|
||||
all = all || Object.create(null);
|
||||
|
||||
return {
|
||||
/**
|
||||
* Register an event handler for the given type.
|
||||
*
|
||||
* @param {String} type Type of event to listen for, or `"*"` for all events
|
||||
* @param {Function} handler Function to call in response to given event
|
||||
* @memberOf mitt
|
||||
*/
|
||||
on: function on(type , handler ) {
|
||||
(all[type] || (all[type] = [])).push(handler);
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove an event handler for the given type.
|
||||
*
|
||||
* @param {String} type Type of event to unregister `handler` from, or `"*"`
|
||||
* @param {Function} handler Handler function to remove
|
||||
* @memberOf mitt
|
||||
*/
|
||||
off: function off(type , handler ) {
|
||||
if (all[type]) {
|
||||
all[type].splice(all[type].indexOf(handler) >>> 0, 1);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Invoke all handlers for the given type.
|
||||
* If present, `"*"` handlers are invoked after type-matched handlers.
|
||||
*
|
||||
* @param {String} type The event type to invoke
|
||||
* @param {Any} [evt] Any value (object is recommended and powerful), passed to each handler
|
||||
* @memberOf mitt
|
||||
*/
|
||||
emit: function emit(type , evt ) {
|
||||
(all[type] || []).slice().map(function (handler) { handler(evt); });
|
||||
(all['*'] || []).slice().map(function (handler) { handler(type, evt); });
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default mitt;
|
||||
//# sourceMappingURL=mitt.es.js.map
|
1
node_modules/mitt/dist/mitt.es.js.map
generated
vendored
Normal file
1
node_modules/mitt/dist/mitt.es.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"mitt.es.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
2
node_modules/mitt/dist/mitt.js
generated
vendored
Normal file
2
node_modules/mitt/dist/mitt.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
function n(n){return n=n||Object.create(null),{on:function(c,e){(n[c]||(n[c]=[])).push(e)},off:function(c,e){n[c]&&n[c].splice(n[c].indexOf(e)>>>0,1)},emit:function(c,e){(n[c]||[]).slice().map(function(n){n(e)}),(n["*"]||[]).slice().map(function(n){n(c,e)})}}}module.exports=n;
|
||||
//# sourceMappingURL=mitt.js.map
|
1
node_modules/mitt/dist/mitt.js.map
generated
vendored
Normal file
1
node_modules/mitt/dist/mitt.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":[],"names":[],"mappings":"","file":"mitt.js"}
|
2
node_modules/mitt/dist/mitt.umd.js
generated
vendored
Normal file
2
node_modules/mitt/dist/mitt.umd.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):n.mitt=e()}(this,function(){function n(n){return n=n||Object.create(null),{on:function(e,t){(n[e]||(n[e]=[])).push(t)},off:function(e,t){n[e]&&n[e].splice(n[e].indexOf(t)>>>0,1)},emit:function(e,t){(n[e]||[]).slice().map(function(n){n(t)}),(n["*"]||[]).slice().map(function(n){n(e,t)})}}}return n});
|
||||
//# sourceMappingURL=mitt.umd.js.map
|
1
node_modules/mitt/dist/mitt.umd.js.map
generated
vendored
Normal file
1
node_modules/mitt/dist/mitt.umd.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":[],"names":[],"mappings":"","file":"mitt.umd.js"}
|
49
node_modules/mitt/mitt.d.ts
generated
vendored
Normal file
49
node_modules/mitt/mitt.d.ts
generated
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
declare var mitt: mitt.MittStatic;
|
||||
|
||||
declare module "mitt" {
|
||||
export = mitt;
|
||||
}
|
||||
|
||||
declare namespace mitt {
|
||||
type Handler = (event?: any) => void;
|
||||
type WildcardHandler = (type?: string, event?: any) => void;
|
||||
|
||||
interface MittStatic {
|
||||
(all?: {[key: string]: Array<Handler>}): Emitter;
|
||||
}
|
||||
|
||||
interface Emitter {
|
||||
/**
|
||||
* Register an event handler for the given type.
|
||||
*
|
||||
* @param {string} type Type of event to listen for, or `"*"` for all events.
|
||||
* @param {Handler} handler Function to call in response to the given event.
|
||||
*
|
||||
* @memberOf Mitt
|
||||
*/
|
||||
on(type: string, handler: Handler): void;
|
||||
on(type: "*", handler: WildcardHandler): void;
|
||||
|
||||
/**
|
||||
* Function to call in response to the given event
|
||||
*
|
||||
* @param {string} type Type of event to unregister `handler` from, or `"*"`
|
||||
* @param {Handler} handler Handler function to remove.
|
||||
*
|
||||
* @memberOf Mitt
|
||||
*/
|
||||
off(type: string, handler: Handler): void;
|
||||
off(type: "*", handler: WildcardHandler): void;
|
||||
|
||||
/**
|
||||
* Invoke all handlers for the given type.
|
||||
* If present, `"*"` handlers are invoked prior to type-matched handlers.
|
||||
*
|
||||
* @param {string} type The event type to invoke
|
||||
* @param {any} [event] An event object, passed to each handler
|
||||
*
|
||||
* @memberOf Mitt
|
||||
*/
|
||||
emit(type: string, event?: any): void;
|
||||
}
|
||||
}
|
93
node_modules/mitt/package.json
generated
vendored
Normal file
93
node_modules/mitt/package.json
generated
vendored
Normal file
@ -0,0 +1,93 @@
|
||||
{
|
||||
"name": "mitt",
|
||||
"version": "1.2.0",
|
||||
"description": "Tiny 200b functional Event Emitter / pubsub.",
|
||||
"jsnext:main": "dist/mitt.es.js",
|
||||
"module": "dist/mitt.es.js",
|
||||
"main": "dist/mitt.js",
|
||||
"umd:main": "dist/mitt.umd.js",
|
||||
"scripts": {
|
||||
"bump": "standard-version",
|
||||
"testonly": "mocha --require esm --require flow-remove-types/register test/**/*.js",
|
||||
"lint": "eslint src test",
|
||||
"test": "flow && npm run lint && npm run testonly",
|
||||
"build": "npm-run-all --silent clean -p rollup -p minify:* -s docs size",
|
||||
"clean": "rimraf dist",
|
||||
"rollup": "rollup -c",
|
||||
"minify:cjs": "uglifyjs $npm_package_main -cm toplevel -o $npm_package_main -p relative --in-source-map ${npm_package_main}.map --source-map ${npm_package_main}.map",
|
||||
"minify:umd": "uglifyjs $npm_package_umd_main -cm -o $npm_package_umd_main -p relative --in-source-map ${npm_package_umd_main}.map --source-map ${npm_package_umd_main}.map",
|
||||
"docs": "documentation readme src/index.js --section API -q",
|
||||
"size": "echo \"Gzipped Size: $(strip-json-comments --no-whitespace $npm_package_main | gzip-size | pretty-bytes)\"",
|
||||
"release": "npm run build -s && npm run bump && git push --follow-tags origin master && npm publish"
|
||||
},
|
||||
"repository": "developit/mitt",
|
||||
"keywords": [
|
||||
"events",
|
||||
"eventemitter",
|
||||
"pubsub"
|
||||
],
|
||||
"homepage": "https://github.com/developit/mitt",
|
||||
"authors": [
|
||||
"Jason Miller <jason@developit.ca>"
|
||||
],
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"src",
|
||||
"dist",
|
||||
"mitt.d.ts"
|
||||
],
|
||||
"babel": {
|
||||
"presets": [
|
||||
"es2015",
|
||||
"stage-0"
|
||||
],
|
||||
"plugins": [
|
||||
"transform-flow-strip-types"
|
||||
]
|
||||
},
|
||||
"eslintConfig": {
|
||||
"parser": "babel-eslint",
|
||||
"extends": "eslint:recommended",
|
||||
"env": {
|
||||
"browser": true,
|
||||
"mocha": true,
|
||||
"es6": true
|
||||
},
|
||||
"globals": {
|
||||
"expect": true
|
||||
},
|
||||
"rules": {
|
||||
"semi": [
|
||||
2,
|
||||
"always"
|
||||
]
|
||||
}
|
||||
},
|
||||
"typings": "./mitt.d.ts",
|
||||
"devDependencies": {
|
||||
"babel-core": "^6.9.1",
|
||||
"babel-eslint": "^7.1.1",
|
||||
"babel-plugin-transform-flow-strip-types": "^6.21.0",
|
||||
"babel-preset-es2015": "^6.9.0",
|
||||
"babel-preset-stage-0": "^6.5.0",
|
||||
"chai": "^3.5.0",
|
||||
"documentation": "^4.0.0-beta4",
|
||||
"eslint": "^3.13.1",
|
||||
"esm": "^3.2.25",
|
||||
"flow-bin": "^0.38.0",
|
||||
"flow-remove-types": "^1.2.0",
|
||||
"gzip-size-cli": "^1.0.0",
|
||||
"mocha": "^3.2.0",
|
||||
"npm-run-all": "^2.1.1",
|
||||
"pretty-bytes-cli": "^2.0.0",
|
||||
"rimraf": "^2.5.2",
|
||||
"rollup": "^0.41.4",
|
||||
"rollup-plugin-buble": "^0.15.0",
|
||||
"rollup-plugin-flow": "^1.1.1",
|
||||
"sinon": "^1.17.4",
|
||||
"sinon-chai": "^2.8.0",
|
||||
"standard-version": "^4.0.0",
|
||||
"strip-json-comments-cli": "^1.0.1",
|
||||
"uglify-js": "^2.6.2"
|
||||
}
|
||||
}
|
61
node_modules/mitt/src/index.js
generated
vendored
Normal file
61
node_modules/mitt/src/index.js
generated
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
// @flow
|
||||
// An event handler can take an optional event argument
|
||||
// and should not return a value
|
||||
type EventHandler = (event?: any) => void;
|
||||
type WildCardEventHandler = (type: string, event?: any) => void
|
||||
|
||||
// An array of all currently registered event handlers for a type
|
||||
type EventHandlerList = Array<EventHandler>;
|
||||
type WildCardEventHandlerList = Array<WildCardEventHandler>;
|
||||
// A map of event types and their corresponding event handlers.
|
||||
type EventHandlerMap = {
|
||||
'*'?: WildCardEventHandlerList,
|
||||
[type: string]: EventHandlerList,
|
||||
};
|
||||
|
||||
/** Mitt: Tiny (~200b) functional event emitter / pubsub.
|
||||
* @name mitt
|
||||
* @returns {Mitt}
|
||||
*/
|
||||
export default function mitt(all: EventHandlerMap) {
|
||||
all = all || Object.create(null);
|
||||
|
||||
return {
|
||||
/**
|
||||
* Register an event handler for the given type.
|
||||
*
|
||||
* @param {String} type Type of event to listen for, or `"*"` for all events
|
||||
* @param {Function} handler Function to call in response to given event
|
||||
* @memberOf mitt
|
||||
*/
|
||||
on(type: string, handler: EventHandler) {
|
||||
(all[type] || (all[type] = [])).push(handler);
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove an event handler for the given type.
|
||||
*
|
||||
* @param {String} type Type of event to unregister `handler` from, or `"*"`
|
||||
* @param {Function} handler Handler function to remove
|
||||
* @memberOf mitt
|
||||
*/
|
||||
off(type: string, handler: EventHandler) {
|
||||
if (all[type]) {
|
||||
all[type].splice(all[type].indexOf(handler) >>> 0, 1);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Invoke all handlers for the given type.
|
||||
* If present, `"*"` handlers are invoked after type-matched handlers.
|
||||
*
|
||||
* @param {String} type The event type to invoke
|
||||
* @param {Any} [evt] Any value (object is recommended and powerful), passed to each handler
|
||||
* @memberOf mitt
|
||||
*/
|
||||
emit(type: string, evt: any) {
|
||||
(all[type] || []).slice().map((handler) => { handler(evt); });
|
||||
(all['*'] || []).slice().map((handler) => { handler(type, evt); });
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user