Comparing version 0.1.2 to 0.1.3
74
index.js
@@ -1,72 +0,2 @@ | ||
'use strict'; | ||
var debug = require('./debug.js')('geotool:loadsync'); | ||
var loadsync = function loadsync(params) { | ||
debug && debug(' + constructor begin ...'); | ||
var self = this; | ||
params = params || {}; | ||
params.states = params.states || []; | ||
params.timeout = params.timeout || 0; | ||
var timeoutHandler = null; | ||
var initTimeoutHandler = function(timeout) { | ||
if (typeof(timeout) === 'number') { | ||
if (timeoutHandler) { | ||
clearTimeout(timeoutHandler); | ||
timeoutHandler = null; | ||
} | ||
params.timeout = timeout; | ||
if (params.timeout > 0) { | ||
timeoutHandler = setTimeout(function() { | ||
params.states = []; | ||
self.check(); | ||
}, params.timeout); | ||
} | ||
} | ||
} | ||
this.define = function(opts) { | ||
opts = opts || {}; | ||
debug && debug('define: %s', JSON.stringify(opts)); | ||
if (opts.states instanceof Array) { | ||
params.states = opts.states || params.states; | ||
} | ||
initTimeoutHandler(opts.timeout); | ||
return this; | ||
} | ||
var callbacks = []; | ||
this.ready = function(callback) { | ||
debug && debug('append a new callback'); | ||
if (typeof(callback) === 'function') { | ||
callbacks.push(callback); | ||
} | ||
return this.check(); | ||
} | ||
this.check = function(state) { | ||
debug && debug('check state: %s', state); | ||
var stateInd = params.states.indexOf(state); | ||
if (stateInd >= 0) { | ||
params.states.splice(stateInd, 1); | ||
} | ||
if (params.states.length === 0) { | ||
debug && debug('ready, run all of callbacks'); | ||
callbacks.forEach(function(callback) { | ||
callback(); | ||
}); | ||
} | ||
return this; | ||
} | ||
initTimeoutHandler(params.timeout); | ||
debug && debug(' - constructor end!'); | ||
}; | ||
module.exports = new loadsync(); | ||
var Flow = require('./lib/flow'); | ||
module.exports = new Flow(); |
{ | ||
"name": "loadsync", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Load javascript libraries in browser synchronously", | ||
@@ -10,3 +10,10 @@ "main": "index.js", | ||
"author": "acegik", | ||
"license": "ISC" | ||
"license": "ISC", | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"mocha": "^3.2.0" | ||
}, | ||
"dependencies": { | ||
"debug": "^2.6.0" | ||
} | ||
} |
@@ -24,6 +24,10 @@ # loadsync | ||
```javascript | ||
loadsync.define({ | ||
states: ['STATE1', 'STATE2', 'STATE3'], | ||
timeout: 9000 | ||
}); | ||
loadsync.reset([{ | ||
name: 'TIMEOUT', | ||
cards: ['STATE1', 'STATE2', 'STATE3'], | ||
timeout: 500 | ||
}, { | ||
name: 'NO_TIMEOUT', | ||
cards: ['STATE3', 'STATE4', 'STATE5'] | ||
}]); | ||
``` | ||
@@ -35,4 +39,4 @@ | ||
loadsync.ready(function() { | ||
// code should be run after STATE1, STATE2, STATE3 have been done | ||
}); | ||
// code should be run after STATE1, STATE2, STATE3 have been checked | ||
}, 'TIMEOUT'); | ||
``` | ||
@@ -43,3 +47,3 @@ | ||
```javascript | ||
loadsync.check('STATE1'); | ||
loadsync.check('STATE1', 'TIMEOUT'); | ||
``` | ||
@@ -50,7 +54,7 @@ | ||
```javascript | ||
loadsync.check('STATE2'); | ||
loadsync.check('STATE2', 'TIMEOUT'); | ||
``` | ||
```javascript | ||
loadsync.check('STATE3'); | ||
loadsync.check('STATE3', '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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
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
5110
7
126
57
1
2
4
1
+ Addeddebug@^2.6.0
+ Addeddebug@2.6.9(transitive)
+ Addedms@2.0.0(transitive)