diff options
author | isaacs <i@izs.me> | 2012-08-14 11:27:57 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2012-08-14 11:27:57 +0400 |
commit | 7b26c04df16d2042193dd94be37874ad9895caa2 (patch) | |
tree | 09609d437e31a80c2aed7925e555d7c55d2f6ae1 | |
parent | 8808e63533da631835d803ffc809705c1016edad (diff) |
once@1.1.1
-rw-r--r-- | node_modules/once/LICENSE | 27 | ||||
-rw-r--r-- | node_modules/once/README.md | 33 | ||||
-rw-r--r-- | node_modules/once/once.js | 19 | ||||
-rw-r--r-- | node_modules/once/package.json | 35 | ||||
-rw-r--r-- | node_modules/once/test/once.js | 18 | ||||
-rw-r--r-- | package.json | 6 |
6 files changed, 136 insertions, 2 deletions
diff --git a/node_modules/once/LICENSE b/node_modules/once/LICENSE new file mode 100644 index 000000000..0c44ae716 --- /dev/null +++ b/node_modules/once/LICENSE @@ -0,0 +1,27 @@ +Copyright (c) Isaac Z. Schlueter ("Author") +All rights reserved. + +The BSD License + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS +BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/node_modules/once/README.md b/node_modules/once/README.md new file mode 100644 index 000000000..e833b83d2 --- /dev/null +++ b/node_modules/once/README.md @@ -0,0 +1,33 @@ +# once + +Only call a function once. + +## usage + +```javascript +var once = require('once') + +function load (file, cb) { + cb = once(cb) + loader.load('file') + loader.once('load', cb) + loader.once('error', cb) +} +``` + +Or add to the Function.prototype in a responsible way: + +```javascript +// only has to be done once +require('once').proto() + +function load (file, cb) { + cb = cb.once() + loader.load('file') + loader.once('load', cb) + loader.once('error', cb) +} +``` + +Ironically, the prototype feature makes this module twice as +complicated as necessary. diff --git a/node_modules/once/once.js b/node_modules/once/once.js new file mode 100644 index 000000000..effc50a47 --- /dev/null +++ b/node_modules/once/once.js @@ -0,0 +1,19 @@ +module.exports = once + +once.proto = once(function () { + Object.defineProperty(Function.prototype, 'once', { + value: function () { + return once(this) + }, + configurable: true + }) +}) + +function once (fn) { + var called = false + return function () { + if (called) return + called = true + return fn.apply(this, arguments) + } +} diff --git a/node_modules/once/package.json b/node_modules/once/package.json new file mode 100644 index 000000000..22671632e --- /dev/null +++ b/node_modules/once/package.json @@ -0,0 +1,35 @@ +{ + "name": "once", + "version": "1.1.1", + "description": "Run a function exactly one time", + "main": "once.js", + "directories": { + "test": "test" + }, + "dependencies": {}, + "devDependencies": { + "tap": "~0.3.0" + }, + "scripts": { + "test": "tap test/*.js" + }, + "repository": { + "type": "git", + "url": "git://github.com/isaacs/once" + }, + "keywords": [ + "once", + "function", + "one", + "single" + ], + "author": { + "name": "Isaac Z. Schlueter", + "email": "i@izs.me", + "url": "http://blog.izs.me/" + }, + "license": "BSD", + "readme": "# once\n\nOnly call a function once.\n\n## usage\n\n```javascript\nvar once = require('once')\n\nfunction load (file, cb) {\n cb = once(cb)\n loader.load('file')\n loader.once('load', cb)\n loader.once('error', cb)\n}\n```\n\nOr add to the Function.prototype in a responsible way:\n\n```javascript\n// only has to be done once\nrequire('once').proto()\n\nfunction load (file, cb) {\n cb = cb.once()\n loader.load('file')\n loader.once('load', cb)\n loader.once('error', cb)\n}\n```\n\nIronically, the prototype feature makes this module twice as\ncomplicated as necessary.\n", + "_id": "once@1.1.1", + "_from": "once" +} diff --git a/node_modules/once/test/once.js b/node_modules/once/test/once.js new file mode 100644 index 000000000..f0291a44f --- /dev/null +++ b/node_modules/once/test/once.js @@ -0,0 +1,18 @@ +var test = require('tap').test +var once = require('../once.js') + +test('once', function (t) { + var f = 0 + var foo = once(function (g) { + t.equal(f, 0) + f ++ + return f + g + this + }) + for (var i = 0; i < 1E3; i++) { + t.same(f, i === 0 ? 0 : 1) + var g = foo.call(1, 1) + t.same(g, i === 0 ? 3 : undefined) + t.same(f, 1) + } + t.end() +}) diff --git a/package.json b/package.json index 295f7b0ec..18cd8436d 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,8 @@ "osenv": "0", "lockfile": ">=0.2", "retry": "~0.6.0", - "couch-login": "~0.1.6" + "couch-login": "~0.1.6", + "once": "~1.1.1" }, "bundleDependencies": [ "semver", @@ -105,7 +106,8 @@ "osenv", "lockfile", "retry", - "couch-login" + "couch-login", + "once" ], "devDependencies": { "ronn": "~0.3.6", |