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 @@ }; |
{ | ||
"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'); | ||
``` |
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
2955
65
53