summaryrefslogtreecommitdiff
path: root/api/jsapi.txt
diff options
context:
space:
mode:
authorportix <portix@gmx.net>2012-11-08 00:01:09 +0100
committerportix <portix@gmx.net>2012-11-08 00:01:09 +0100
commit8e730b559ce0d957b8a1f637a601c8a1c36b2d2a (patch)
tree64d87b3ac9ecb1e1f583e8ffc5451fa45126c9b9 /api/jsapi.txt
parentc745499e3b994c8ccc503dada279df60f5618f4b (diff)
downloaddwb-8e730b559ce0d957b8a1f637a601c8a1c36b2d2a.zip
Allow paths and empty callbacks in require
Diffstat (limited to 'api/jsapi.txt')
-rw-r--r--api/jsapi.txt55
1 files changed, 54 insertions, 1 deletions
diff --git a/api/jsapi.txt b/api/jsapi.txt
index 55d112f7..7abdf176 100644
--- a/api/jsapi.txt
+++ b/api/jsapi.txt
@@ -150,7 +150,9 @@ Load modules defined with <<provide>>.
::
-_names_;; An array of module names or null to get all modules.
+_names_;; An array of module names or null to get all modules, a module name can
+also contain a path, the path must be seperated with a +!+ from the module name,
+see also <<Modules>> for details.
_callback_;; A callback function that is called after initialization of all
scripts and modules. The parameters of the callback function correspond to the
names array. If +names+ is null the function is called with one parameter that
@@ -2169,6 +2171,57 @@ require(null, function(modules) {
});
-------
+It is also possible to specify a path in the name array. The name then follows
+the format +name!path+:
+
+[source,javascript]
+-------
+#!javascript
+
+require(["foo!/path/to/foo"], function(foo) {
+ io.print(foo.bar); // 37
+});
+-------
+
+./path/to/foo
+[source,javascript]
+-------
+#!javascript
+
+provide("foo", { bar : 37 });
+-------
+
+The resolution chain is as follows, first all modules defined with +provide+ and
+module names requested by +require+ are stored. If all scripts have been loaded
+the requirements are resolved. If a requirement contains a path and the module
+isn't defined yet the module will be loaded, if it is already defined the path
+is ignored and the stored module will be resolved:
+
+[source,javascript]
+-------
+#!javascript
+
+require(["foo!/path/to/foo"], function(foo) {
+ io.print(foo.bar); // 42
+});
+provide("foo", { bar : 42 });
+-------
+
+[source,javascript]
+-------
+#!javascript
+
+require(["foo"], function(foo) {
+ io.print(foo); // undefined
+});
+require(["foo!/path/to/foo"]);
+
+require(["foo"], function(foo) {
+ io.print(foo); // { bar : 37 }
+});
+-------
+
+
[[Extensions]]
== Extensions ==
*dwb* provides the possibility to load extensions.