Comparing version 0.1.5 to 0.1.6
@@ -17,14 +17,7 @@ 'use strict'; | ||
var item = data[idx] || {}; | ||
if (!(item.name instanceof String) && !(item.name.length > 0)) { | ||
ok = false; | ||
break; | ||
} | ||
if (!(item.cards instanceof Array)) { | ||
ok = false; | ||
break; | ||
} | ||
if (!(item.name instanceof String) && !(item.name.length > 0)) ok = false; | ||
if (!(item.cards instanceof Array)) ok = false; | ||
if (!ok) break; | ||
} | ||
if (!ok) { | ||
if (throwException) throw new Error(); | ||
} | ||
if (!ok && throwException) throw new Error(); | ||
return ok; | ||
@@ -37,3 +30,3 @@ } | ||
steps = steps || []; | ||
debug.enabled && debug('steps: %s', JSON.stringify(steps, null, 2)); | ||
debug.enabled && debug('reset() - steps: %s', JSON.stringify(steps)); | ||
if (!validate(steps)) { | ||
@@ -57,4 +50,4 @@ debug.enabled && debug('invalid reset() parameters'); | ||
self[methodName] = function(card, step) { | ||
if (debug && methodName === 'check') { | ||
debug.enabled && debug('card: %s / step: %s', card, step); | ||
if (debug.enabled && methodName === 'check') { | ||
debug(methodName + '() - card: %s / step: %s', card, step); | ||
} | ||
@@ -72,6 +65,7 @@ var method = stepObjects[step] && stepObjects[step][methodName]; | ||
var instance = null; | ||
Flow.singleton = function() { | ||
Flow.instance = Flow.singleton = function() { | ||
instance = instance || new Flow(); | ||
return instance; | ||
} | ||
module.exports = Flow; |
@@ -18,2 +18,3 @@ 'use strict'; | ||
} | ||
state.isTimeout = false; | ||
state.timeout = timeout; | ||
@@ -31,3 +32,3 @@ if (state.timeout > 0) { | ||
params = params || {}; | ||
debug.enabled && debug('reset: %s', JSON.stringify(params)); | ||
debug.enabled && debug('reset() with: %s', JSON.stringify(params)); | ||
@@ -42,3 +43,3 @@ state.cards = (params.cards instanceof Array) ? params.cards : []; | ||
this.ready = function(callback) { | ||
debug.enabled && debug('append a new callback'); | ||
debug.enabled && debug('ready() - append a new callback'); | ||
if (typeof(callback) === 'function') { | ||
@@ -51,3 +52,3 @@ callbacks.push(callback); | ||
this.check = function(card) { | ||
debug.enabled && debug('check card: %s', card || 'N/A'); | ||
debug.enabled && debug('check() - for card: %s', card || 'N/A'); | ||
var cardInd = state.cards.indexOf(card); | ||
@@ -60,5 +61,5 @@ if (cardInd >= 0 && !state.isTimeout) { | ||
if (state.isTimeout) { | ||
debug.enabled && debug('step has timeout, ready() will be called'); | ||
debug.enabled && debug('check() - step is expired, run callbacks'); | ||
} else { | ||
debug.enabled && debug('ready, run all of callbacks'); | ||
debug.enabled && debug('check() - all of cards has been checked'); | ||
} | ||
@@ -65,0 +66,0 @@ var cbs = callbacks || []; |
{ | ||
"name": "loadsync", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "Load javascript libraries in browser synchronously", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -18,3 +18,3 @@ # loadsync | ||
```javascript | ||
var loadsync = require('loadsync'); | ||
var Loadsync = require('loadsync'); | ||
``` | ||
@@ -25,2 +25,19 @@ | ||
```javascript | ||
var loadsync = new Loadsync([{ | ||
name: 'TIMEOUT', | ||
cards: ['STATE1', 'STATE2', 'STATE3'], | ||
timeout: 500 | ||
}, { | ||
name: 'NO_TIMEOUT', | ||
cards: ['STATE3', 'STATE4', 'STATE5'] | ||
}]); | ||
``` | ||
Or reset it: | ||
```javascript | ||
// create empty loadsync instance | ||
// var loadsync = new Loadsync(); | ||
// reset steps and begin a new flow | ||
loadsync.reset([{ | ||
@@ -27,0 +44,0 @@ name: 'TIMEOUT', |
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
5695
77
123