pax_global_header00006660000000000000000000000064132761747440014531gustar00rootroot0000000000000052 comment=da22dc644d2ec25da634b5a161881bef1e3a0ff1 sparkles-1.0.1/000077500000000000000000000000001327617474400133545ustar00rootroot00000000000000sparkles-1.0.1/.editorconfig000066400000000000000000000003261327617474400160320ustar00rootroot00000000000000# http://editorconfig.org root = true [*] indent_style = space indent_size = 2 charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true end_of_line = lf [*.md] trim_trailing_whitespace = false sparkles-1.0.1/.eslintrc000066400000000000000000000000301327617474400151710ustar00rootroot00000000000000{ "extends": "gulp" } sparkles-1.0.1/.gitattributes000066400000000000000000000000161327617474400162440ustar00rootroot00000000000000* text eol=lf sparkles-1.0.1/.gitignore000066400000000000000000000011461327617474400153460ustar00rootroot00000000000000# Logs logs *.log # Runtime data pids *.pid *.seed # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt # Compiled binary addons (http://nodejs.org/api/addons.html) build/Release # Dependency directory # Commenting this out is preferred by some people, see # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- node_modules # Users Environment Variables .lock-wscript # Garbage files .DS_Store sparkles-1.0.1/.npmrc000066400000000000000000000000231327617474400144670ustar00rootroot00000000000000package-lock=false sparkles-1.0.1/.travis.yml000066400000000000000000000002021327617474400154570ustar00rootroot00000000000000sudo: false language: node_js node_js: - '10' - '8' - '6' - '4' - '0.12' - '0.10' after_script: - npm run coveralls sparkles-1.0.1/LICENSE000066400000000000000000000021711327617474400143620ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2014 Blaine Bublitz and Eric Schoffstall Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. sparkles-1.0.1/README.md000066400000000000000000000036741327617474400146450ustar00rootroot00000000000000

# sparkles [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Travis Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url] Namespaced global event emitter ## Usage Sparkles exports a function that returns a singleton `EventEmitter`. This EE can be shared across your application, whether or not node loads multiple copies. ```js var sparkles = require('sparkles')(); // make sure to call the function sparkles.on('my-event', function(evt){ console.log('my-event handled', evt); }); sparkles.emit('my-event', { my: 'event' }); ``` ## API ### sparkles(namespace) Returns an EventEmitter that is shared amongst the provided namespace. If no namespace is provided, returns a default EventEmitter. ### sparkles.exists(namespace); Checks whether a namespace exists and returns true or false. ## Why the name? This is a "global emitter"; shortened: "glitter" but it was already taken; so we got sparkles instead :smile: ## License MIT [downloads-image]: http://img.shields.io/npm/dm/sparkles.svg [npm-url]: https://www.npmjs.com/package/sparkles [npm-image]: http://img.shields.io/npm/v/sparkles.svg [travis-url]: https://travis-ci.org/gulpjs/sparkles [travis-image]: http://img.shields.io/travis/gulpjs/sparkles.svg?label=travis-ci [appveyor-url]: https://ci.appveyor.com/project/gulpjs/sparkles [appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/sparkles.svg?label=appveyor [coveralls-url]: https://coveralls.io/r/gulpjs/sparkles [coveralls-image]: http://img.shields.io/coveralls/gulpjs/sparkles/master.svg [gitter-url]: https://gitter.im/gulpjs/gulp [gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg sparkles-1.0.1/appveyor.yml000066400000000000000000000007541327617474400157520ustar00rootroot00000000000000# http://www.appveyor.com/docs/appveyor-yml # http://www.appveyor.com/docs/lang/nodejs-iojs environment: matrix: # node.js - nodejs_version: "0.10" - nodejs_version: "0.12" - nodejs_version: "4" - nodejs_version: "6" - nodejs_version: "8" - nodejs_version: "10" install: - ps: Install-Product node $env:nodejs_version - npm install test_script: - node --version - npm --version - cmd: npm test build: off # build version format version: "{build}" sparkles-1.0.1/index.js000066400000000000000000000014321327617474400150210ustar00rootroot00000000000000'use strict'; var EventEmitter = require('events').EventEmitter; var sparklesNamespace = 'store@sparkles'; var defaultNamespace = 'default'; function getStore() { var store = global[sparklesNamespace]; if (!store) { store = global[sparklesNamespace] = {}; } return store; } function getEmitter(namespace) { var store = getStore(); namespace = namespace || defaultNamespace; var ee = store[namespace]; if (!ee) { ee = store[namespace] = new EventEmitter(); ee.setMaxListeners(0); ee.remove = function remove() { ee.removeAllListeners(); delete store[namespace]; }; } return ee; } function exists(namespace) { var store = getStore(); return !!(store[namespace]); } module.exports = getEmitter; module.exports.exists = exists; sparkles-1.0.1/package.json000066400000000000000000000016461327617474400156510ustar00rootroot00000000000000{ "name": "sparkles", "version": "1.0.1", "description": "Namespaced global event emitter", "author": "Gulp Team (http://gulpjs.com/)", "contributors": [ "Blaine Bublitz " ], "repository": "gulpjs/sparkles", "license": "MIT", "engines": { "node": ">= 0.10" }, "main": "index.js", "files": [ "LICENSE", "index.js" ], "scripts": { "lint": "eslint .", "pretest": "npm run lint", "test": "mocha --async-only", "cover": "istanbul cover _mocha --report lcovonly", "coveralls": "npm run cover && istanbul-coveralls" }, "dependencies": {}, "devDependencies": { "eslint": "^2.13.0", "eslint-config-gulp": "^3.0.1", "expect": "^1.20.2", "istanbul": "^0.4.3", "istanbul-coveralls": "^1.0.3", "mocha": "^3.5.3" }, "keywords": [ "ee", "emitter", "events", "global", "namespaced" ] } sparkles-1.0.1/test/000077500000000000000000000000001327617474400143335ustar00rootroot00000000000000sparkles-1.0.1/test/.eslintrc000066400000000000000000000000351327617474400161550ustar00rootroot00000000000000{ "extends": "gulp/test" } sparkles-1.0.1/test/exists.js000066400000000000000000000006241327617474400162120ustar00rootroot00000000000000'use strict'; var expect = require('expect'); var sparkles = require('../'); describe('sparkles.exists()', function() { it('checks if a namespace has been defined', function(done) { expect(sparkles.exists('test')).toBe(false); var ee = sparkles('test'); expect(sparkles.exists('test')).toBe(true); ee.remove(); expect(sparkles.exists('test')).toBe(false); done(); }); }); sparkles-1.0.1/test/index.js000066400000000000000000000014621327617474400160030ustar00rootroot00000000000000'use strict'; var expect = require('expect'); var sparkles = require('../'); function noop() {} describe('sparkles()', function() { var ee; beforeEach(function(done) { ee = sparkles(); done(); }); afterEach(function(done) { ee.remove(); done(); }); it('will attach the sparkles store namespace to global', function(done) { expect(global['store@sparkles']).toExist(); done(); }); it('will attach an event emitter to the sparkles store default namespace', function(done) { expect(global['store@sparkles']).toIncludeKey('default'); done(); }); it('removes the event emitter from the store when remove is called', function(done) { ee.on('test', noop); ee.remove(); expect(global['store@sparkles']).toNotIncludeKey('default'); done(); }); }); sparkles-1.0.1/test/namespace.js000066400000000000000000000015321327617474400166260ustar00rootroot00000000000000'use strict'; var expect = require('expect'); var EventEmitter = require('events').EventEmitter; describe('namespace', function() { beforeEach(function(done) { global['store@sparkles'] = {}; done(); }); afterEach(function(done) { delete global['store@sparkles']; done(); }); it('should use an EE from sparkles namespace if it already exists', function(done) { var ee = global['store@sparkles'].default = new EventEmitter(); ee.custom = 'ee'; var sparkles = require('../')(); expect(sparkles.custom).toEqual('ee'); done(); }); it('should allow custom namespaces', function(done) { var ee = global['store@sparkles'].customNamespace = new EventEmitter(); ee.custom = true; var sparkles = require('../')('customNamespace'); expect(sparkles.custom).toEqual(true); done(); }); });