{ "_args": [ [ { "raw": "fbemitter@^2.1.1", "scope": null, "escapedName": "fbemitter", "name": "fbemitter", "rawSpec": "^2.1.1", "spec": ">=2.1.1 <3.0.0", "type": "range" }, "/Volumes/2009-SSD/GT2/GT2-iOS/node_modules/expo" ] ], "_from": "fbemitter@>=2.1.1 <3.0.0", "_id": "fbemitter@2.1.1", "_inCache": true, "_location": "/fbemitter", "_nodeVersion": "6.4.0", "_npmOperationalInternal": { "host": "packages-16-east.internal.npmjs.com", "tmp": "tmp/fbemitter-2.1.1.tgz_1472874581984_0.025550180580466986" }, "_npmUser": { "name": "zpao", "email": "paul@oshannessy.com" }, "_npmVersion": "3.10.3", "_phantomChildren": {}, "_requested": { "raw": "fbemitter@^2.1.1", "scope": null, "escapedName": "fbemitter", "name": "fbemitter", "rawSpec": "^2.1.1", "spec": ">=2.1.1 <3.0.0", "type": "range" }, "_requiredBy": [ "/expo" ], "_resolved": "https://registry.npmjs.org/fbemitter/-/fbemitter-2.1.1.tgz", "_shasum": "523e14fdaf5248805bb02f62efc33be703f51865", "_shrinkwrap": null, "_spec": "fbemitter@^2.1.1", "_where": "/Volumes/2009-SSD/GT2/GT2-iOS/node_modules/expo", "bugs": { "url": "https://github.com/facebook/emitter/issues" }, "dependencies": { "fbjs": "^0.8.4" }, "description": "Facebook's EventEmitter is a simple emitter implementation that prioritizes speed and simplicity. It is conceptually similar to other emitters like Node's EventEmitter, but the precise APIs differ. More complex abstractions like the event systems used on facebook.com and m.facebook.com can be built on top of EventEmitter as well DOM event systems.", "devDependencies": { "babel-core": "^5.8.34", "del": "^2.2.0", "fbjs-scripts": "^0.5.0", "gulp": "^3.9.0", "gulp-babel": "^5.3.0", "gulp-flatten": "^0.2.0", "jest-cli": "^0.8.2", "object-assign": "^4.0.1", "run-sequence": "^1.1.5" }, "directories": {}, "dist": { "shasum": "523e14fdaf5248805bb02f62efc33be703f51865", "tarball": "https://registry.npmjs.org/fbemitter/-/fbemitter-2.1.1.tgz" }, "files": [ "LICENSE", "PATENTS", "README.md", "index.js", "lib/" ], "gitHead": "c2b3571840e982db3da7dfcc6592442b203e4f52", "homepage": "https://github.com/facebook/emitter#readme", "jest": { "modulePathIgnorePatterns": [ "/lib/", "/node_modules/" ], "persistModuleRegistryBetweenSpecs": true, "preprocessorIgnorePatterns": [ "/node_modules/" ], "rootDir": "", "scriptPreprocessor": "scripts/jest/preprocessor.js", "testPathDirs": [ "/src" ], "unmockedModulePathPatterns": [ "/node_modules/", "/src/(?!(__forks__/fetch.js$|fetch/))" ] }, "keywords": [ "clientside" ], "license": "BSD-3-Clause", "main": "index.js", "maintainers": [ { "name": "fb", "email": "opensource+npm@fb.com" }, { "name": "kyldvs", "email": "kyldvs@gmail.com" }, { "name": "zpao", "email": "paul@oshannessy.com" } ], "name": "fbemitter", "optionalDependencies": {}, "readme": "# EventEmitter\n\nFacebook's EventEmitter is a simple emitter implementation that prioritizes speed and simplicity. It is conceptually similar to other emitters like Node's EventEmitter, but the precise APIs differ. More complex abstractions like the event systems used on facebook.com and m.facebook.com can be built on top of EventEmitter as well DOM event systems.\n\n## API Concepts\n\nEventEmitter's API shares many concepts with other emitter APIs. When events are emitted through an emitter instance, all listeners for the given event type are invoked.\n\n```js\nvar emitter = new EventEmitter();\nemitter.addListener('event', function(x, y) { console.log(x, y); });\nemitter.emit('event', 5, 10); // Listener prints \"5 10\".\n```\n\nEventEmitters return a subscription for each added listener. Subscriptions provide a convenient way to remove listeners that ensures they are removed from the correct emitter instance.\n\n```js\nvar subscription = emitter.addListener('event', listener);\nsubscription.remove();\n```\n\n## Usage\n\nFirst install the `fbemitter` package via `npm`, then you can require or import it.\n\n```js\nvar {EventEmitter} = require('fbemitter');\nvar emitter = new EventEmitter();\n\n```\n\n## Building from source\n\nOnce you have the repository cloned, building a copy of `fbemitter` is easy, just run `gulp build`. This assumes you've installed `gulp` globally with `npm install -g gulp`.\n\n```sh\ngulp build\n```\n\n## API\n\n### `constructor()`\n\nCreate a new emitter using the class' constructor. It accepts no arguments.\n\n```js\nvar {EventEmitter} = require('fbemitter');\nvar emitter = new EventEmitter();\n```\n\n### `addListener(eventType, callback)`\n\nRegister a specific callback to be called on a particular event. A token is returned that can be used to remove the listener.\n\n```js\nvar token = emitter.addListener('change', (...args) => {\n console.log(...args);\n});\n\nemitter.emit('change', 10); // 10 is logged\ntoken.remove();\nemitter.emit('change', 10); // nothing is logged\n```\n\n### `once(eventType, callback)`\n\nSimilar to `addListener()` but the callback is removed after it is invoked once. A token is returned that can be used to remove the listener.\n\n```js\nvar token = emitter.once('change', (...args) => {\n console.log(...args);\n});\n\nemitter.emit('change', 10); // 10 is logged\nemitter.emit('change', 10); // nothing is logged\n```\n\n### `removeAllListeners(eventType)`\n\nRemoves all of the registered listeners. `eventType` is optional, if provided only listeners for that event type are removed.\n\n```js\nvar token = emitter.addListener('change', (...args) => {\n console.log(...args);\n});\n\nemitter.removeAllListeners();\nemitter.emit('change', 10); // nothing is logged\n```\n\n### `listeners(eventType)`\n\nReturn an array of listeners that are currently registered for the given event type.\n\n### `emit(eventType, ...args)`\n\nEmits an event of the given type with the given data. All callbacks that are listening to the particular event type will be notified.\n\n```js\nvar token = emitter.addListener('change', (...args) => {\n console.log(...args);\n});\n\nemitter.emit('change', 10); // 10 is logged\n```\n\n### `__emitToSubscription(subscription, eventType, ...args)`\n\nIt is reasonable to extend `EventEmitter` in order to inject some custom logic that you want to do on every callback that is called during an emit, such as logging, or setting up error boundaries. `__emitToSubscription()` is exposed to make this possible.\n\n```js\nclass MyEventEmitter extends EventEmitter {\n __emitToSubscription(subscription, eventType) {\n var args = Array.prototype.slice.call(arguments, 2);\n var start = Date.now();\n subscription.listener.apply(subscription.context, args);\n var time = Date.now() - start;\n MyLoggingUtility.log('callback-time', {eventType, time});\n }\n}\n```\n\nAnd then you can create instances of `MyEventEmitter` and use it like a standard `EventEmitter`. If you just want to log on each emit and not on each callback called during an emit you can override `emit()` instead of this method.\n\n## Contribute\n\nThe main purpose of this repository is to share Facebook's implementation of an emitter. Please see React's [contributing article](https://github.com/facebook/react/blob/master/CONTRIBUTING.md), which generally applies to `fbemitter`, if you are interested in submitting a pull request.\n", "readmeFilename": "README.md", "repository": { "type": "git", "url": "git+https://github.com/facebook/emitter.git" }, "scripts": { "build": "gulp build", "prepublish": "npm run build", "test": "NODE_ENV=test jest" }, "version": "2.1.1" }