-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
async-js-bootstrap-template.js
63 lines (59 loc) · 1.91 KB
/
async-js-bootstrap-template.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict'
/**
* @provides The bootstrap template to resolve dependencies of an js app
* before its invocation while that app along w/ dependencies
* are loaded asynchronously
*
* @author https://juliyvchirkov.github.io
* @release https://github.com/juliyvchirkov/async-js-bootstrap-template/releases/tag/v0.0.21
* @bugs https://github.com/juliyvchirkov/async-js-bootstrap-template/issues
* @license MIT
*
* @see README.md
*/
/**
* The outer frame of the whole thing
*
* @param {object} global The global namespace (i.e. “window” / “self”)
* @param {function} factory An app
*
* @returns {void}
*/
;(function (global, factory) {
/**
* Resolves dependencies of an app. Invokes that app as soon as
* all dependencies are resolved
*
* @returns { … } Invoked app if its dependencies are completely
* resolved, itself deferred for 0.1s otherwise
*/
;(function bootstrap () {
return [
/**
* The array of strings
*
* Each string defines a dependency to be resolved
* (like “_”, “FormValidation.Framework.Bootstrap”,
* “jQuery.fn.modal” etc)
*
* Dependencies gotta be defined by their complete
* namespace relative to the global one. The order
* of dependencies within the array doesn't matter
*/
].every(function (dependency) {
var context = global
var proppath = dependency.split('.')
while (proppath.length) {
context = context[proppath.shift()]
if (!/[fo]/.test((typeof context)[0])) {
return false
}
}
return true
}) ? factory() : setTimeout(bootstrap, 100)
})()
})(this, function () {
/**
* An app code goes here
*/
})