Add Flow type annotations (#23)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* Add flowtype annotations * Add flow to test script
authored by Brandon Dail · committed by Jason Miller · parent f147246 · Browse files · 6 files·+53 added−9 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+53 added−9 removed
- other:+53 added−9 removed
Provenance
- Commit
377d6f4- Tree
082f409- Author
Brandon Dail <aweary@users.noreply.github.com>- Committer
Jason Miller <developit@users.noreply.github.com>- Parent
f147246
6 files changed+53 added−9 removed
modified:src/index.js+15 added-4 removed
123456789101112131415516171819203 unmodified lines242526271728293031323 unmodified lines363738392940414243445 unmodified lines5051525343545556575859// @flow// An event handler can take an optional event argument// and should not return a valuetype EventHandler = (event?: any) => void;// An array of all currently registered event handlers for a typetype EventHandlerList = Array<EventHandler>;// A map of event types and their corresponding event handlers.type EventHandlerMap = { [type: string]: EventHandlerList,};
/** Mitt: Tiny (~200b) functional event emitter / pubsub. * @name mitt * @returns {Mitt} */export default function mitt(all) {export default function mitt(all: EventHandlerMap) { all = all || Object.create(null);
return { /**3 unmodified lines * @param {Function} handler Function to call in response to given event * @return {Object} the `mitt` instance for chaining * @memberOf mitt */ on(type, handler) { on(type: string, handler: EventHandler) { (all[type] || (all[type] = [])).push(handler); },
/**3 unmodified lines * @param {Function} handler Handler function to remove * @return {Object} the `mitt` instance for chaining * @memberOf mitt */ off(type, handler) { off(type: string, handler: EventHandler) { let e = all[type] || (all[type] = []); e.splice(e.indexOf(handler) >>> 0, 1); },
5 unmodified lines * @param {Any} [evt] Any value (object is recommended and powerful), passed to each handler * @return {Object} the `mitt` instance for chaining * @memberof mitt */ emit(type, evt) { emit(type: string, evt: EventHandler) { (all[type] || []).map((handler) => { handler(evt); }); (all['*'] || []).map((handler) => { handler(type, evt); }); } };}modified:.babelrc+4 added-1 removed
1 {2- "presets": ["es2015", "stage-0"]2+ "presets": ["es2015", "stage-0"],3+ "plugins": [4+ "transform-flow-strip-types"5+ ]6 }added:.flowconfig+7 added
1+[ignore]2+3+[include]4+5+[libs]6+7+[options]modified:package.json+4 added-1 removed
5 unmodified lines678910101112131437 unmodified lines525354555657585960616263646566676869707172737475762 unmodified lines5 unmodified lines "jsnext:main": "src/index.js", "main": "dist/mitt.js", "umd:main": "dist/mitt.umd.js", "scripts": { "test": "eslint src test && mocha --compilers js:babel-register test/**/*.js", "test": "flow && eslint src test && mocha --compilers js:babel-register test/**/*.js", "build": "npm-run-all clean -p rollup:* -p minify:* -s docs size", "clean": "rimraf dist && mkdirp dist", "rollup:cjs": "rollup -c rollup.config.js -m -f cjs -n $npm_package_amdName $npm_package_jsnext_main -o $npm_package_main", "rollup:umd": "rollup -c rollup.config.js -m -f umd -n $npm_package_amdName $npm_package_jsnext_main -o $npm_package_umd_main",37 unmodified lines "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", "babel-register": "^6.9.0", "chai": "^3.5.0", "documentation": "^4.0.0-beta4", "eslint": "^3.13.1", "flow-bin": "^0.38.0", "gzip-size-cli": "^1.0.0", "mkdirp": "^0.5.1", "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", "strip-json-comments-cli": "^1.0.1", "uglify-js": "^2.6.2"2 unmodified linesmodified:rollup.config.js+2 added
12345678910import buble from 'rollup-plugin-buble';import flow from 'rollup-plugin-flow';
export default { useStrict: false, plugins: [ flow(), buble() ]};modified:yarn.lock+21 added-3 removed
668 unmodified lines669 dependencies:670 babel-plugin-syntax-export-extensions "^6.8.0"671 babel-runtime "^6.0.0"672 673-babel-plugin-transform-flow-strip-types@^6.3.13:673+babel-plugin-transform-flow-strip-types@^6.21.0, babel-plugin-transform-flow-strip-types@^6.3.13:674 version "6.21.0"675 resolved "https://registry.yarnpkg.com/babel-plugin-transform-flow-strip-types/-/babel-plugin-transform-flow-strip-types-6.21.0.tgz#2eea3f8b5bb234339b47283feac155cfb237b948"676 dependencies:677 babel-plugin-syntax-flow "^6.18.0"188 unmodified lines866 dependencies:867 babel-core "^6.0.14"868 object-assign "^4.0.0"869 870-babylon@^6.11.0, babylon@^6.13.0, babylon@^6.5.2:870+babylon@^6.11.0, babylon@^6.13.0, babylon@^6.15.0, babylon@^6.5.2:871 version "6.15.0"872 resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.15.0.tgz#ba65cfa1a80e1759b0e89fb562e27dccae70348e"873 874 bail@^1.0.0:807 unmodified lines1682 del "^2.0.2"1683 graceful-fs "^4.1.2"1684 write "^0.2.1"1685 1686+flow-bin@^0.38.0:1687+ version "0.38.0"1688+ resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.38.0.tgz#3ae096d401c969cc8b5798253fb82381e2d0237a"1689+1690+flow-remove-types@^1.1.0:1691+ version "1.2.0"1692+ resolved "https://registry.yarnpkg.com/flow-remove-types/-/flow-remove-types-1.2.0.tgz#c285516eabba72177a1b10bfb58f6ffb675a8877"1693+ dependencies:1694+ babylon "^6.15.0"1695+ vlq "^0.2.1"1696+1697 for-in@^0.1.5:1698 version "0.1.6"1699 resolved "https://registry.yarnpkg.com/for-in/-/for-in-0.1.6.tgz#c9f96e89bfad18a545af5ec3ed352a1d9e5b4dc8"1700 1674 unmodified lines3375 dependencies:3376 buble "^0.15.0"3377 rollup-pluginutils "^1.5.0"3378 3368-rollup-pluginutils@^1.5.0:3379+rollup-plugin-flow@^1.1.1:3380+ version "1.1.1"3381+ resolved "https://registry.yarnpkg.com/rollup-plugin-flow/-/rollup-plugin-flow-1.1.1.tgz#6ce568f1dd559666b77ab76b4bae251407528db6"3382+ dependencies:3383+ flow-remove-types "^1.1.0"3384+ rollup-pluginutils "^1.5.1"3385+3386+rollup-pluginutils@^1.5.0, rollup-pluginutils@^1.5.1:3387 version "1.5.2"3388 resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-1.5.2.tgz#1e156e778f94b7255bfa1b3d0178be8f5c552408"3389 dependencies:3390 estree-walker "^0.2.1"724 unmodified lines