Code

The Code interface holds the deployment configuration of the current playground: the routes it deploys to, the editors who may redeploy it, and the title field of the Code dialog. It is a global of the playground window, available in the browser console and in io.eval.js files.

Code is the Code dialog itself (Set Routes… and Set Title…) with a few extra properties and one method, so changing its properties changes what the dialog shows. Setting Code.D does not deploy anything: edge.save.limit() deploys to every route in it.

Instance properties

Code.D

An array of strings: the routes the playground deploys to, such as ['new'] or ['example.com/docs']. Reading it returns a new array of the unique, valid, normalized routes; invalid entries are left out. See Route syntax.

Assigning an array replaces every route. The routes are stored in ascending string order, so after an assignment, a reload or an opened link, Code.D[0], the first route, is the alphabetically first one. Code.D = undefined removes all routes. Assign an array of strings: null throws a TypeError, and a string is not treated as one route.

The first route is the default for edge.open(), edge.size() and edge.versions(), it names the agent work folder, and it is the title when no title is set. Because the getter returns a copy, change the list by assigning a new array: Code.D = [...Code.D, 'my-site/docs'].

Note: Setting Code.D is not a deploy, and removing a route from the list does not delete what was deployed there. Delete first, while the route is still listed: edge.save.limit({ path: '/del' }).

Code.W

An array of strings naming the deployment's editors. Reading it returns the unique, valid entries; assigning an array replaces the list. Code.W is stored and sorted like Code.D. Values are lowercased and the first run of whitespace is removed.

Entries name an account, an email domain, or any signed-in account with *. See Editors for entry syntax, permissions, and adding or removing collaborators.

Setting Code.W changes the playground configuration. The owner must deploy to publish editor-list changes to the chosen routes. An editor must keep the saved list unchanged when redeploying.

Code.T Experimental

A string: the Title field of the Code dialog. It is not the playground title: assigning Code.T alone changes nothing until the dialog is submitted. A value equal to the first route is stored as an empty string.

Code.edit() copies the current title into it when the dialog opens and writes it back when you press Set. To change the title from code, assign title.

Code.v Experimental Read only

A string: the current state of the playground as an uncompressed URL, with the source, title, layout and settings. Keys that equal their defaults are left out. The address bar switches to a compressed form for long sources; Code.v is always the plain form, so it can be very long. See Linking and embedding.

Instance methods

Code.edit() Experimental

Opens the Code dialog and resolves when it closes. This is the dialog that Set Routes… (Alt+R) and Set Title… (Alt+T) open.

js
await Code.edit()
await Code.edit(options)

The optional options object has these properties:

select Optional

A CSS selector for the element to focus once the dialog is open. The default '#T' focuses the Title field; '#D > :first-child' focuses the first route.

suggest Optional

A string to put into the focused field.

save Optional

A boolean value: when truthy, the confirm button reads Deploy instead of Set. The dialog never deploys by itself; the button only closes it.

It returns a Promise. After Set it resolves to { T, D, F, W }: the title as a string, and the routes, the deployment tags (the dialog has no visible Tags field) and the editors as arrays of strings. After Cancel or Esc it resolves to null and the title, routes and editors return to the values they had when the dialog opened.

The promise settles only when a person closes the dialog, so an io.eval.js that awaits it waits for that person. Submitting stores the title, and the routes and editors are sorted again, as in Code.D.

Route syntax

A route is a host plus an optional path: demo/docs names https://demo.rt.ht/docs/, and example.com/docs names https://example.com/docs/. See Routes for the grammar, normalization rules and examples.

Examples

Reading the configuration

Write this to io.eval.js, or run it in the playground's console. Reading changes nothing. The object literal is wrapped in parentheses so that it is an expression.

js
({ routes: Code.D, editors: Code.W, title, url: Code.v.length })

Setting routes and editors

js
Code.D = ['my-site', 'my-site/docs'];
Code.W = ['ada@example.com', 'example.org'];
Code.D // ['my-site', 'my-site/docs'], in this order

Asking for a route in the dialog

js
const result = await Code.edit({ select: '#D > :first-child', save: true });
result ?? 'cancelled'

Specifications

Not part of any specification. Code is an RTCode.io playground global. The playground normalizes route hosts with the browser's URL parser; see the URL Standard.

Availability

FeaturePlaygroundRTEdge.netNotes
Code.DYesNoDeployed pages do not have the playground globals.
Code.WYesNoSent with every deploy.
Code.TYesNoExperimental.
Code.vYesNoExperimental. Read only.
Code.edit()YesNoExperimental. Waits for a person to close the dialog.

See also