Editor code and published code
What runs in the editor, what runs in a published design and how the design is published.
On this page
UI Builder runs your component in two places. The editor runs exports.make of editor.html, and the published design runs exports.make of render.html.
What each one does
| Editor | Published design | |
|---|---|---|
| Purpose | Show what the component will look like, and react to its settings. | Do the real work: read input, keep the value, talk to other components. |
| Settings change | Yes, emits configure. | No. |
Last argument of make | true | undefined |
UIBuilder.editor | true | not set |
Keep the editor code light: a field can show its label and a placeholder without working. Textbox shows a grey box in the editor and a real input in the published design.
One source for both is possible: use the last argument of make to tell them apart.
exports.make = function(instance, config, element, cls, iseditor) {
if (!iseditor) {
instance.state.bind = true;
}
};How a design is published
When the user selects Publish, UI Builder:
- Serializes every instance with its configuration. Each instance can change its data in the
stringifyhandler. - Replaces each component in
componentswith the address of itsrender.html. - With Download components' to the source in compiling on in Global settings, downloads each
render.htmland puts its source into the design, without the readme and the settings.
The published page loads render.html from its address, so the file must stay there, on a server that allows requests from the page (CORS). A component created in the editor has no address: its source goes into the design.
Clean the configuration
Remove what the published design does not need in stringify. The second argument is true when the design is published.
instance.on('stringify', function(meta, isbuild) {
if (isbuild)
delete meta.config.note;
});Where a published design runs
The page from Download HTML loads the Total.js UI library and the UI Builder runtime and builds the design with UIBuilder.build(). An app can do the same with the _render.json file. See App reference.