Page Reference

Table of Contents


Introduction

Pages form the bulk of an app. A Page instance contains the following:


Page creation

Syntax

ctl.createPage(info)

Pages are created using the ctl.createPage() factory function.


Instance methods

close()

Syntax

close()

The Controller calls the close() method when the page is dismissed. The page can use it to remove event listeners or do other cleanup from open(). The default close() method does nothing.


component()

Syntax

component()

The Nav page or other navigation component calls the component() method to retrieve a Component subclass that will display this page's content in the View. The default component() returns a Component class whose Component render() method returns the results of calling the Page instance's render() method. Therefore, a page can supply a simpler render() method instead of implementing a full Component subclass.

Return value

A Component subclass.


deactivate()

Syntax

deactivate()

The Controller calls the deactivate() method when a new popup page is opened on top of this page. It returns the state values required to restore this page's state when the pages on top are dismissed. The default deactivate() method returns null.

Return value

Any JavaScript type. This value is used as the state argument for reactivate(state) when the page is reactivated.


getSavedState()

Syntax

getSavedState(state)

The Controller calls each page's getSavedState() method when the application state is being saved to local device storage or in the cloud. The method adds the information required to restore the page's state variables to the state object.

The default getSavedState() method adds the information for the page's state variables marked for saving locally or globally (see getSavedSvs()). State variables that are unit siblings other than the current unit are excluded. The value stored for each state variable's ID key is the result of calling the state variable's getSavedState() method.

Parameters

Return value

The state object.


getSavedSvMonitors()

Syntax

getSavedSvMonitors()

Returns the array of SvMonitors for the state variables returned by getSavedSvs(). The array is created the first time the method is called and then reused. Used by the default hasChanged() method.


getSavedSvs()

Syntax

getSavedSvs()

Returns the array of the page's state variables that are marked for saving locally or globally (their save property is 'local' or 'global'). Unit siblings are included only for the current unit. The list is recomputed on every call because it depends on the current unit. The default getSavedState() and setSavedState() methods use it.


hasChanged()

Syntax

hasChanged()

The Controller calls the hasChanged() method after each synchronization to determine whether the page's saved state has changed, and so whether the app state needs to be saved. It is unrelated to Model recomputation. The default hasChanged() method uses the SvMonitors for the state variables marked for saving locally or globally (see getSavedSvMonitors()). It interrogates every monitor, so each is current for the next inquiry, and returns true if any of their hasChanged() methods returns true.

Return value

True if the page's saved state variables have changed since the last time hasChanged() was called, otherwise false.


init()

Syntax

init()

The Controller calls the init() method after the application is fully loaded on startup and all application pages and their associated state variables are created. The state variables hold their default values because the previous session's values are restored after all pages are initialized. This allows the page to do any pre-setup before being opened.


open()

Syntax

open(arg)

The Controller calls the open() method when a page is opened. This allows the page to do any pre-setup before Model computation. The default open() method returns an empty string.

If the info object passed to ctl.createPage() supplies its own open(), the Controller wraps it so that it also sets the page's isOpen and isActive properties. The same applies to close(), reactivate(), and deactivate(), so those methods need not maintain the two properties themselves.

Parameters

Return value

A Template, a Component, or a string that is the content to display, as for render().


reactivate()

Syntax

reactivate(state)

The Controller calls the reactivate() method when the popup pages above the page are dismissed, and the page is now the topmost page. The state argument is the value the deactivate() method returned previously for this page.

Parameters


render()

Syntax

render()

The default component() returns a Component class whose Component render() method returns the results of calling the Page instance's render() method. Therefore, a page can supply a simpler render() method instead of implementing a full Component subclass.

Return value

A Template object, a string, a number, a DOM node, a Component object, or an array containing a mix of these types that represents the contents of the page when opened.


renderHelp()

Syntax

renderHelp()

When initialized, the built-in Help page automatically collects the templates returned by calling the renderHelp() method. It then uses that information, along with the page's pageId and title, as a help topic.

Return value

A Template object, a string, a number, a DOM node, a Component object, or an array containing a mix of these types that represents the help information displayed when the page is selected as the help topic.


renderTold()

Syntax

renderTold()

Optional. A page that contributes to the emailed flight planning results (TOLD) defines this method. The told module calls it for each page in its toldPageIds list, converts the result to plain text, and mails the text from the Email button.

Return value

A <PlainText> template containing one <Pl> element for each line of text. See Writing a page's TOLD lines.


isSpinning()

Syntax

isSpinning(name)

Returns true if the named spinner is running. A RefreshButton uses it when it renders so that a re-render while a fetch is in progress keeps spinning.

Parameters

Return value

A Boolean.


registerSpinner()

Syntax

registerSpinner(name, comp)

Adds a RefreshButton component to the set that is synchronized with the named spinner. The component calls this when it mounts.

Parameters


setSavedState()

Syntax

setSavedState(state)

If state is null, all of the page's saved state variables are reset to their defaults.
The Controller calls each page's setSavedState() method when the application state is being restored from local device storage or from the cloud. The method uses the information in the state object to restore the page's state variables. The state object uses the state variable ID as a key for each state variable's information.

The default setSavedState() method restores the state of the page's state variables marked for saving locally or globally. The state is restored by calling the state variable's setSavedState() method passing the state object's value for the state variables. A state variable that is missing from state is set to its default value. If the restored value is invalid and the state variable has no options, it is also set to its default value.

Parameters


startSpinner()

Syntax

startSpinner(name)

Starts the named spinner on this page to show that a fetch is in progress. A page may have more than one spinner, so each is named for the thing it is refreshing (e.g., 'metar'). The name matches the spinner property of the RefreshButton components on the page. Starting a spinner that is already running, or one with no button rendered, does nothing.

Parameters


stopSpinner()

Syntax

stopSpinner(name)

Stops the named spinner on this page.

Parameters


unregisterSpinner()

Syntax

unregisterSpinner(name, comp)

Removes a RefreshButton component from the set synchronized with the named spinner. The component calls this when it unmounts.

Parameters


upgradeSavedState()

Syntax

upgradeSavedState(state, version)

The Controller calls each page's upgradeSavedState() method after the application state to be restored has been retrieved from local device storage or from the cloud. The method updates the page's state variable information in the state object as required to upgrade the information of the information saved by an older application version to the current application version. The method interprets the version string and updates the relevant keys and values as required.

See also:

Parameters

Return value

Returns true if the upgrade was successful. Returns false if the information was corrupt or too old.


Instance properties

computeInfo

The computeInfo array from the info object passed to ctl.createPage(). Defaults to an empty array.

Value

An array.


isOpen

True if the page is opened, whether activated or deactivated.

Value

A Boolean.


isActive

True if the page is opened and activated.

Value

A Boolean.


pageId

The page's ID.

Value

A string.


stateVarInfo

The stateVarInfo array from the info object passed to ctl.createPage(). Defaults to an empty array.

Value

An array.


tipInfo

The tipInfo array from the info object passed to ctl.createPage(). Defaults to an empty array.

Value

An array.


sv

A state variable namespace containing the state variables whose IDs have this page's pageId prefix. The Controller creates it at startup.

Value

An object.


takesOpenArg

True if the page's open() method declares an argument, meaning that a navigation reference such as cb.NAME passes it its argument.

Value

A Boolean.


title

The page's title. Defaults to an empty string.

Value

A string.