can-queues
Advanced tools
Comparing version 1.1.4 to 1.2.0
@@ -206,4 +206,4 @@ var QUnit = require( 'steal-qunit' ); | ||
setFnName(derivedChild_queueUpdate, 'derivedChild_queueUpdate'); | ||
map = { | ||
@@ -424,1 +424,63 @@ name: "map", | ||
}); | ||
QUnit.test(".lastTask()", function(){ | ||
function notify () { | ||
var lastTask = queues.lastTask(); | ||
QUnit.equal(lastTask.fn,notify); | ||
} | ||
queues.enqueueByQueue({ | ||
"notify": [notify], | ||
}); | ||
}); | ||
QUnit.test(".stack(lastTask)", function(){ | ||
var lastTask; | ||
var outerNotify, innerNotify; | ||
queues.enqueueByQueue({ | ||
"notify": [outerNotify = function notify () { | ||
queues.enqueueByQueue({ | ||
"notify": [innerNotify = function notify () { | ||
lastTask = queues.lastTask(); | ||
}], | ||
"domUI": [function domUI () { | ||
var stack = queues.stack(lastTask); | ||
QUnit.equal(stack[0].fn, outerNotify); | ||
QUnit.equal(stack[1].fn, innerNotify); | ||
}] | ||
}); | ||
}] | ||
}); | ||
}); | ||
QUnit.test(".runAsTask(fn)", function(){ | ||
var lastTask; | ||
var outerNotify, innerNotify; | ||
var obj = {}; | ||
var thing = function(){ | ||
queues.enqueueByQueue({ | ||
"notify": [innerNotify = function notify () { | ||
lastTask = queues.lastTask(); | ||
}], | ||
"domUI": [function domUI () { | ||
var stack = queues.stack(lastTask); | ||
QUnit.equal(stack[0].fn, outerNotify); | ||
QUnit.equal(stack[1].fn, thing); | ||
QUnit.deepEqual(stack[1].args[0], 1); | ||
QUnit.equal(stack[1].context, obj); | ||
QUnit.equal(stack[2].fn, innerNotify); | ||
}] | ||
}); | ||
}; | ||
var thingQueued = queues.runAsTask(thing); | ||
queues.enqueueByQueue({ | ||
"notify": [outerNotify = function notify () { | ||
thingQueued.call(obj, 1); | ||
}] | ||
}); | ||
}); |
@@ -107,2 +107,24 @@ "use strict"; | ||
}, | ||
runAsTask: function(fn, reasonLog){ | ||
//!steal-remove-start | ||
if(process.env.NODE_ENV !== 'production') { | ||
return function(){ | ||
queueState.lastTask = { | ||
fn: fn, | ||
context: this, | ||
args: arguments, | ||
meta: { | ||
reasonLog: typeof reasonLog === "function" ? reasonLog.apply(this, arguments): reasonLog, | ||
parentTask: queueState.lastTask, | ||
stack: {name: "RUN_AS"} | ||
} | ||
}; | ||
var ret = fn.apply(this, arguments); | ||
queueState.lastTask = queueState.lastTask && queueState.lastTask.meta.parentTask; | ||
return ret; | ||
}; | ||
} | ||
//!steal-remove-end | ||
return fn; | ||
}, | ||
enqueueByQueue: function enqueueByQueue ( fnByQueue, context, args, makeMeta, reasonLog ) { | ||
@@ -128,6 +150,9 @@ if ( fnByQueue ) { | ||
}, | ||
lastTask: function(){ | ||
return queueState.lastTask; | ||
}, | ||
// Currently an internal method that provides the task stack. | ||
// Returns an array with the first task as the first item. | ||
stack: function () { | ||
var current = queueState.lastTask; | ||
stack: function (task) { | ||
var current = task || queueState.lastTask; | ||
var stack = []; | ||
@@ -142,4 +167,4 @@ while ( current ) { | ||
}, | ||
logStack: function () { | ||
var stack = this.stack(); | ||
logStack: function (task) { | ||
var stack = this.stack(task); | ||
stack.forEach( function ( task, i ) { | ||
@@ -146,0 +171,0 @@ var meta = task.meta; |
@@ -7,3 +7,3 @@ @function can-queues.logStack logStack | ||
@signature `queues.logStack( [type] )` | ||
@signature `queues.logStack()` | ||
@@ -10,0 +10,0 @@ `logStack()` is a very useful debugging tool for discovering why a particular piece of code |
{ | ||
"name": "can-queues", | ||
"version": "1.1.4", | ||
"version": "1.2.0", | ||
"description": "A light weight JavaScript task queue", | ||
@@ -5,0 +5,0 @@ "homepage": "", |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
234859
43
866
0
16