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.1 to 0.1.2

31

index.js

@@ -7,10 +7,35 @@ 'use strict';

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 || {};
params.states = opts.states || params.states;
debug && debug('define states: %s', JSON.stringify(params.states));
debug && debug('define: %s', JSON.stringify(opts));
if (opts.states instanceof Array) {
params.states = opts.states || params.states;
}
initTimeoutHandler(opts.timeout);
return this;

@@ -43,2 +68,4 @@ }

initTimeoutHandler(params.timeout);
debug && debug(' - constructor end!');

@@ -45,0 +72,0 @@ };

2

package.json
{
"name": "loadsync",
"version": "0.1.1",
"version": "0.1.2",
"description": "Load javascript libraries in browser synchronously",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -5,1 +5,49 @@ # loadsync

## Installation
(Your web fronend project should use npm to manage libraries)
```shell
$ npm install --save loadsync
```
## Usage
Include `loadsync` library:
```javascript
var loadsync = require('loadsync');
```
Declare States and timeout:
```javascript
loadsync.define({
states: ['STATE1', 'STATE2', 'STATE3'],
timeout: 9000
});
```
Define the ready callback function after all of states have been checked:
```javascript
loadsync.ready(function() {
// code should be run after STATE1, STATE2, STATE3 have been done
});
```
Check each state that has been done (`STATE1` for example):
```javascript
loadsync.check('STATE1');
```
(the same with others: `STATE2`, `STATE3`):
```javascript
loadsync.check('STATE2');
```
```javascript
loadsync.check('STATE3');
```
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