Comparing version 0.1.4 to 0.1.5
'use strict'; | ||
var debug = require('./debug.js')('loadsync:Flow'); | ||
var debug = require('debug')('loadsync:Flow'); | ||
var Step = require('./step'); | ||
var Flow = function Flow(steps) { | ||
debug && debug(' + constructor begin ...'); | ||
debug.enabled && debug(' + constructor begin ...'); | ||
var self = this; | ||
@@ -36,5 +36,5 @@ steps = steps || []; | ||
steps = steps || []; | ||
debug && debug('steps: %s', JSON.stringify(steps, null, 2)); | ||
debug.enabled && debug('steps: %s', JSON.stringify(steps, null, 2)); | ||
if (!validate(steps)) { | ||
debug && debug('invalid reset() parameters'); | ||
debug.enabled && debug('invalid reset() parameters'); | ||
return; | ||
@@ -50,13 +50,13 @@ } | ||
}); | ||
debug && debug('stepKeys: %s', JSON.stringify(Object.keys(stepObjects))); | ||
debug.enabled && debug('stepKeys: %s', JSON.stringify(Object.keys(stepObjects))); | ||
}; | ||
['ready', 'check'].forEach(function(methodName) { | ||
debug && debug('methodName: %s', methodName); | ||
debug.enabled && debug('methodName: %s', methodName); | ||
self[methodName] = function(card, step) { | ||
if (debug && methodName === 'check') { | ||
debug && debug('card: %s / step: %s', card, step); | ||
debug.enabled && debug('card: %s / step: %s', card, step); | ||
} | ||
var method = stepObjects[step] && stepObjects[step][methodName]; | ||
return (method) ? method.call(stepObjects[step], card) : unresetd; | ||
return (method) ? method.call(stepObjects[step], card) : undefined; | ||
} | ||
@@ -67,3 +67,3 @@ }); | ||
debug && debug(' - constructor end!'); | ||
debug.enabled && debug(' - constructor end!'); | ||
}; | ||
@@ -70,0 +70,0 @@ |
'use strict'; | ||
var debug = require('./debug.js')('loadsync:Step'); | ||
var debug = require('debug')('loadsync:Step'); | ||
var Step = function Step(params) { | ||
debug && debug(' + constructor begin ...'); | ||
debug.enabled && debug(' + constructor begin ...'); | ||
var self = this; | ||
var state = { cards: [], timeout: 0 }; | ||
var state = { cards: [], timeout: 0, isTimeout: false }; | ||
@@ -21,3 +21,3 @@ var timeoutHandler = null; | ||
timeoutHandler = setTimeout(function() { | ||
state.cards = []; | ||
state.isTimeout = true; | ||
self.check(); | ||
@@ -31,3 +31,3 @@ }, state.timeout); | ||
params = params || {}; | ||
debug && debug('reset: %s', JSON.stringify(params)); | ||
debug.enabled && debug('reset: %s', JSON.stringify(params)); | ||
@@ -42,3 +42,3 @@ state.cards = (params.cards instanceof Array) ? params.cards : []; | ||
this.ready = function(callback) { | ||
debug && debug('append a new callback'); | ||
debug.enabled && debug('append a new callback'); | ||
if (typeof(callback) === 'function') { | ||
@@ -51,9 +51,14 @@ callbacks.push(callback); | ||
this.check = function(card) { | ||
debug && debug('check card: %s', card || 'N/A'); | ||
debug.enabled && debug('check card: %s', card || 'N/A'); | ||
var cardInd = state.cards.indexOf(card); | ||
if (cardInd >= 0) { | ||
if (cardInd >= 0 && !state.isTimeout) { | ||
state.cards.splice(cardInd, 1); | ||
} | ||
if (state.cards.length === 0) { | ||
debug && debug('ready, run all of callbacks'); | ||
if (state.isTimeout || state.cards.length === 0) { | ||
var info = { isTimeout: state.isTimeout, unchecked: state.cards }; | ||
if (state.isTimeout) { | ||
debug.enabled && debug('step has timeout, ready() will be called'); | ||
} else { | ||
debug.enabled && debug('ready, run all of callbacks'); | ||
} | ||
var cbs = callbacks || []; | ||
@@ -63,3 +68,3 @@ callbacks = []; | ||
cbs.forEach(function(callback) { | ||
callback(); | ||
callback(info); | ||
}); | ||
@@ -73,5 +78,5 @@ } | ||
debug && debug(' - constructor end!'); | ||
debug.enabled && debug(' - constructor end!'); | ||
}; | ||
module.exports = Step; |
{ | ||
"name": "loadsync", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Load javascript libraries in browser synchronously", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "node_modules/.bin/mocha test/tdd/*-test.js" | ||
}, | ||
@@ -9,0 +9,0 @@ "author": "acegik", |
@@ -37,4 +37,7 @@ # loadsync | ||
```javascript | ||
loadsync.ready(function() { | ||
loadsync.ready(function(info) { | ||
// code should be run after STATE1, STATE2, STATE3 have been checked | ||
// or there are some cards not be checked (timeout) | ||
// info.isTimeout: true/false | ||
// info.unchecked: list of unchecked cards | ||
}, 'TIMEOUT'); | ||
@@ -41,0 +44,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
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 2 instances in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
5311
2
60
1
6
128