Class: Define

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.
Source:
core.js, line 1623

Parameters:

Name Type Description
id
string The module id.
dependencyIDs
string[] or string Required module ids.
value
Any The module value.
Example
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.
Source:
core.js, line 1979
Type:

Object.<just.Define~id, just.Define~globals_expression>

Methods

addFiles(value)

Assigns values to the files property.
Source:
core.js, line 2006
Parameters:
Name Type Description
value
just.Define.files Files.

addGlobals(value)

Assigns values to the globals property.
Source:
core.js, line 1991
Parameters:
Name Type Description
value
just.Define.globals Globals.

clean()

Removes all defined modules.
Source:
core.js, line 2029

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.
Source:
core.js, line 2068
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'}.

init()

Finds files within the document, adds them, and if some is called "main", it loads it.
Source:
core.js, line 1857

isDefined(id) → {boolean}

Checks if module has been defined.
Source:
core.js, line 2021
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.
Source:
core.js, line 1888
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

file

Any element that references an external source, like an <script> or a <link>.
Source:
core.js, line 1922
Type:

string

file_id

An alias for a url.
Source:
core.js, line 1916
Type:

string

files_expression

A url, or a tag name with a url splitted by an space. By default, "http://..." is the same as "script http://..."
Source:
core.js, line 1929
Type:

string

Examples
Example 1: A url
"http://..."
Example 2: A tag name with a url.
"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.
Source:
core.js, line 1956
Examples
Example 1: A function.
function () { return 1; } // The module value is 1.
Example 2: A string.
"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.
Source:
core.js, line 1867
Parameters:
Name Type Description
error
Error An error if the url is not being loaded.
data
object Some metadata.
Properties
Name Type Description
event
Event The triggered event: "load" or "error".
moduleID
just.Define~id The id passed to just.Define.
url
url The loaded url.