just.Define(idnon-null, dependencyIDs, value)
A module loader: it loads files in order (when needed) and
execute them when all his dependencies became available.
Parameters:
Name
Type
Description
id
string
The module id.
dependencyIDs
string[]
or
string
Required module ids.
value
Any
The module value.
Example
Name | Type | Description |
---|---|---|
id
|
string | The module id. |
dependencyIDs
|
string[] or string | Required module ids. |
value
|
Any | The module value. |
var files = just.Define.findInDocument('data-files');
var fileIDs = Object.keys(files);
just.Define.load(files);
just.Define('some id', fileIDs, function (file1, file2, ...) {
// Loads after all ids have been defined.
});
Members
globals :Object.<just.Define~id, just.Define~globals_expression>
Aliases for ids.
Type:
Object.<just.Define~id, just.Define~globals_expression>
Methods
addFiles(value)
Assigns values to the files property.
Parameters:
Name | Type | Description |
---|---|---|
value
|
just.Define.files | Files. |
addGlobals(value)
Assigns values to the globals property.
Parameters:
Name | Type | Description |
---|---|---|
value
|
just.Define.globals | Globals. |
findInDocument(attributeName, containeropt) → {just.Define.files}
Finds files within the document
by selecting all the elements that contain an specific
attribute and parsing that attribute as a JSON.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
attributeName
|
string | The attribute which defines the files to be loaded. | |
container
[optional] |
Element | document |
Returns:
- Type
- just.Define.files
Example
// Considering the following document:
< body>
< div id='a' data-files='{"[id]": "link a.css"}'>< /div>
< script src='b.js' data-files='{"b": "script [src]"}'>< /script>
< /body>
// then, in js:
findInDocument('data-files');
// Should return {a: 'link a.css', b: 'script b.js'}.
isDefined(id) → {boolean}
Checks if module has been defined.
Parameters:
Name | Type | Description |
---|---|---|
id
|
just.Define~id | The id passed to just.Define. |
Returns:
`true` if defined, `false` otherwise.
- Type
- boolean
load(value)
A function to load files by ids.
Parameters:
Name | Type | Description |
---|---|---|
value
|
just.Define~file_id or just.Define~file_id[] or Object.<just.Define~file_id, just.Define~load_listener> | File ids. |
Type Definitions
files_expression
A url, or a tag name with a url splitted by an space.
By default, "http://..." is the same as "script http://..."
Type:
string
Examples
"http://..."
"link /index.css"; // Note the space in between.
globals_expression()
A function that returns the module value or a string
splitted by '.' that will be accessed
from window.
Examples
function () { return 1; } // The module value is 1.
"a.b"; // accesses to window, then window.a,
// and then returns window.a.b
load_listener(errornon-null, datanon-null)
A function to be called when the file load.
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
error
|
Error | An error if the url is not being loaded. | ||||||||||||
data
|
object | Some metadata.
Properties
|