App reference
The app object of a design and the UIBuilder object of the page, as components and host apps use them.
On this page
Every design on a page is an app. A component reaches it as instance.app. The page that UI Builder publishes keeps it as window.app, so you can try these calls in the console of the browser.
The page also has one UIBuilder object for all designs.
API
method
app.input(id, data, [callback])
Sends data to an input of the design.
app.input(id, data, [callback])| Parameter | Type | Description |
|---|---|---|
id |
String |
The id of the input, for example cid6wh0tx52_set. |
data |
Object |
The data. |
callback? |
Function |
Receives an error text when the instance or the input does not exist. |
app.input('cid6wh0tx52_set', 2, function(err) {
err && console.log(err);
});
method
app.on(name, fn)
Registers a handler of an event of the design.
app.on(name, fn)| Parameter | Type | Description |
|---|---|---|
name |
String |
The name of the event. |
fn |
Function |
The handler. |
The events are output, change, ready and io.
event
app.on('output', function(meta) {})
An instance has sent an output.
app.on('output', function(meta) {})| Parameter | Type | Description |
|---|---|---|
meta |
Object |
The output. |
meta.id is the id of the output in the design, meta.ref its id in the component, meta.data the data, meta.err an error or null, and meta.instance, meta.component and meta.app the objects.
app.on('output', function(meta) {
console.log(meta.id, meta.data);
});
event
app.on('change', function(instance) {})
The state of an instance has changed.
app.on('change', function(instance) {})| Parameter | Type | Description |
|---|---|---|
instance |
Object |
The instance. |
Emitted 50 ms after the last change of each instance.
event
app.on('ready', function() {})
All instances are built.
app.on('ready', function() {})
method
app.find(id)
Finds an instance.
app.find(id)| Parameter | Type | Description |
|---|---|---|
id |
String |
The id, @ and the id, or . and a path. |
Returns Object The instance.
property
app.instances
All instances of the design.
app.instances
property
app.args
The Dynamic arguments of the design.
app.args
property
app.query
The query arguments of the address of the page.
app.query
property
app.schema
The design as it was built.
app.schema
property
app.element
The element of the design, a jQuery object.
app.element
property
UIBuilder.editor
true in the editor, not set in a published design.
UIBuilder.editor
method
UIBuilder.on(name, fn)
Registers a handler for all designs of the page.
UIBuilder.on(name, fn)| Parameter | Type | Description |
|---|---|---|
name |
String |
The name of the event. |
fn |
Function |
The handler. |
output receives the outputs of every design, with the same meta as app.on('output'). app runs when a design is built.
method
UIBuilder.build(target, design, [callback])
Builds a published design into an element.
UIBuilder.build(target, design, [callback])| Parameter | Type | Description |
|---|---|---|
target |
Element |
Where to put the design. |
design |
Object |
The published design, as in _render.json, or its JSON text. |
callback? |
Function |
Receives the app. |
Returns Object The app.
The published page calls it with the content of the design. The design needs components and children; a design that is already on the page is removed first.
AJAX('GET /designs/demo_render.json', function(design) {
UIBuilder.build('#design', design, function(app) {
app.on('output', console.log);
});
});