Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

loadsync

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

loadsync - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

.npmignore

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');
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc