Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2013-10-24 10:27:42 +0400
committerisaacs <i@izs.me>2013-10-24 10:27:42 +0400
commit96d08ed3c0afc5eab50045061d47cebee5cb9edd (patch)
tree05c4df23baa6b050e250a6eb647d8cd78f3bb2b1 /node_modules/once
parent6f218cb9d1b5edc5a1c72cf77a0876c4bcaaeccc (diff)
once@1.3.0
Diffstat (limited to 'node_modules/once')
-rw-r--r--node_modules/once/README.md18
-rw-r--r--node_modules/once/once.js11
-rw-r--r--node_modules/once/package.json12
-rw-r--r--node_modules/once/test/once.js4
4 files changed, 35 insertions, 10 deletions
diff --git a/node_modules/once/README.md b/node_modules/once/README.md
index e833b83d2..a2981ea07 100644
--- a/node_modules/once/README.md
+++ b/node_modules/once/README.md
@@ -31,3 +31,21 @@ function load (file, cb) {
Ironically, the prototype feature makes this module twice as
complicated as necessary.
+
+To check whether you function has been called, use `fn.called`. Once the
+function is called for the first time the return value of the original
+function is saved in `fn.value` and subsequent calls will continue to
+return this value.
+
+```javascript
+var once = require('once')
+
+function load (cb) {
+ cb = once(cb)
+ var stream = createStream()
+ stream.once('data', cb)
+ stream.once('end', function () {
+ if (!cb.called) cb(new Error('not found'))
+ })
+}
+```
diff --git a/node_modules/once/once.js b/node_modules/once/once.js
index effc50a47..0770a73cd 100644
--- a/node_modules/once/once.js
+++ b/node_modules/once/once.js
@@ -10,10 +10,11 @@ once.proto = once(function () {
})
function once (fn) {
- var called = false
- return function () {
- if (called) return
- called = true
- return fn.apply(this, arguments)
+ var f = function () {
+ if (f.called) return f.value
+ f.called = true
+ return f.value = fn.apply(this, arguments)
}
+ f.called = false
+ return f
}
diff --git a/node_modules/once/package.json b/node_modules/once/package.json
index 22671632e..96af3dedf 100644
--- a/node_modules/once/package.json
+++ b/node_modules/once/package.json
@@ -1,6 +1,6 @@
{
"name": "once",
- "version": "1.1.1",
+ "version": "1.3.0",
"description": "Run a function exactly one time",
"main": "once.js",
"directories": {
@@ -29,7 +29,11 @@
"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"
+ "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\nTo check whether you function has been called, use `fn.called`. Once the\nfunction is called for the first time the return value of the original\nfunction is saved in `fn.value` and subsequent calls will continue to\nreturn this value.\n\n```javascript\nvar once = require('once')\n\nfunction load (cb) {\n cb = once(cb)\n var stream = createStream()\n stream.once('data', cb)\n stream.once('end', function () {\n if (!cb.called) cb(new Error('not found'))\n })\n}\n```\n",
+ "readmeFilename": "README.md",
+ "bugs": {
+ "url": "https://github.com/isaacs/once/issues"
+ },
+ "_id": "once@1.3.0",
+ "_from": "once@latest"
}
diff --git a/node_modules/once/test/once.js b/node_modules/once/test/once.js
index f0291a44f..a77951f11 100644
--- a/node_modules/once/test/once.js
+++ b/node_modules/once/test/once.js
@@ -8,10 +8,12 @@ test('once', function (t) {
f ++
return f + g + this
})
+ t.notOk(foo.called)
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.ok(foo.called)
+ t.same(g, 3)
t.same(f, 1)
}
t.end()