Skip to content

Built in Helper Functions

BobDickinson edited this page Oct 8, 2014 · 6 revisions

Synchro provides a number of built-in commands in the Synchro namespace. These are automatically made accessible to Synchro modules (no "require" is necessary).

Synchro.getResourceUrl

Synchro.getResourceUrl(resource)

getResourceUrl uses the resource mapper provided in the Synchro application configuration to resolve resource names to full URLs that can be used to access those resources.

Synchro.navigateTo

Synchro.navigateTo(context, route, params)

navigateToView navigates between Synchro views. The route describes the path to the desired view, and params, if present, is an object that is passed to the IntializeViewModel function of the module being navigated to.

Synchro.pushAndNavigateTo

Synchro.pushAndNavigateTo(context, route, params, state)

pushAndNavigateToView navigates between Synchro views. It works like navigateTo, except that is also pushes the current view on to the back stack, so that it can be accessed later using Synchro.pop or Synchro.popTo. In addition, any state provided will be passed to the InitializeViewModel function of this view when it is navigated back to via Synchro.pop or Synchro.popTo.

Synchro.pop

Synchro.pop(context)

pop navigates to the most recent view stored on the back stack.

Synchro.popTo

Synchro.popTo(context, route)

popTo navigates to the most recent view stored on the back stack which has a route matching the supplied route.

Synchro.showMessage

Synchro.showMessage(context, messageBox)

showMessage causes the client device to show a message using the native message/alert mechanism on the device. Below is an example showing the components of the messageBox:

{
    title: "Caption",
    message: "This is the message",
    options:
    [
        { label: "Ok", command: "doOK" },
        { label: "Cancel" }
    ]
}

The title is optional. The options are also optional. If no options are provided, the message box will have a single Close button that dismisses the message box. Up to three options may be provided. Each option will generate a button with a label as specified in the label attribute of the option. An option with a command attribute will result in the message box being dismissed and that command issued when the corresponding button is clicked. An option without a command attribute result in a button that simply dismisses the message box.

Synchro.waitFor

 Synchro.waitFor(fn, arguments)

waitFor allows for asynchronous calls to functions (asynchronous with respect to Node.js anyway). See docs for wait.for (!!! inline some of that and include an example here)

Synchro.interimUpdate

Synchro.interimUpdate(context)

interimUpdate provides a partial viewModel update back to the client, while allowing the server module to continue processing.

Synchro.isActiveInstance

 Synchro.isActiveInstance(context)

isActiveInstance indicates whether the page/instance being processed is the active instance. If it returns false, that means that the instance that the calling code is processing is not current (has been navigated away from). In this case, no viewModel updates will be sent to the client.

Synchro.getMetrics

Synchro.getMetrics(context)

getMetrics returns a metrics object containing DeviceMetrics and ViewMetrics.