MAS 9.2 series cheatsheet
Every behaviour on this page is measured on our test system, on the MAS 9.2 series. The calls in the code blocks run in the controllers of our Components Explorer, and the two patterns at the end come from the guides.
Where a controller is named#
| Controller | Named on | How many objects |
|---|---|---|
| application controller | <maximo-application controller="…"> | one for the app |
| page controller | <page controller="…"> | one for each page, also when two pages name the same class |
| datasource controller | <maximo-datasource controller="…"> or <json-datasource controller="…"> | one for each datasource that names a class |
| dialog controller | <dialog controller="…"> | one for each dialog that names a class |
The guides for this section are Controller Architecture Overview, AppController vs. PageController.
The lifecycle hooks#
| Hook | On the controller of | Runs |
|---|---|---|
applicationInitialized(app) | the application | once, before any page |
onDatasourceInitialized(ds) | a datasource | once, when its page first opens |
pageInitialized(page, app) | a page | once, on the first visit |
pageResumed(page, app) | a page | on every visit, the first one included |
onBeforeLoadData(ds) | a datasource | before every load |
onAfterLoadData(ds, items) | a datasource | after every load, with the rows |
pagePaused(page, app) | a page | every time the user leaves the page, forward or back |
dialogInitialized(dialog) | a dialog | on the first open |
dialogOpened() | a dialog | on every open |
The rules that go with the table:
- A hook is not waited for. An
asyncpageInitializedof 1.5 seconds finished afterpageResumedhad run. - A hook that throws is caught. The page draws, and the console holds one line that contains “Controller event”.
- The rows arrive after the page hooks. The first load of a bound datasource starts after
pageResumed. - A page that the user leaves stays alive. Its controller, its fields and its state are there on the next visit.
- A dialog controller gets no call on a close. Do the work of a close in the handler of the button.
The guide for this section is Using Lifecycle Hooks Correctly.
Which hook for which job#
| Job | Hook |
|---|---|
| keep the app, set values for the whole app | applicationInitialized |
| keep the page, set values that stay | pageInitialized |
| load or refresh the data of a page | pageResumed |
| clear a form before the user sees it again | pageResumed, or dialogOpened for a dialog |
| configure a datasource once | onDatasourceInitialized |
| change or add to the rows after each load | onAfterLoadData |
| stop a timer, save a draft, remove a subscription | pagePaused |
Who gets a call#
A hook and a click travel the same way: from the controller they belong to, outward.
| The call starts at | It reaches, in this order |
|---|---|
| a hook of a datasource | datasource controller, page controller, application controller |
| a hook of a page | page controller, application controller |
on-click="method" | datasource controller, page controller, application controller |
on-click="datasourceId:method" | the controller of that datasource, then page and application controller |
- Every controller on the path that has a method of that name runs it. A name that exists twice runs twice.
- A button of any page reaches a method that only the application controller has.
- A name that no controller has runs nothing, and nothing tells the user.
The guide for this section is Controller Architecture Overview.
What a handler receives#
| Markup | First parameter | Second parameter |
|---|---|---|
on-click="m" on-click-arg="{{colour: 'teal'}}" | the object | the click event |
on-click="m" on-click-arg="{item}" in a list | the record of the row | the click event |
on-click="m" | the click event | nothing |
on-change="m" on a text-input | the event of the input, once for each keystroke | nothing |
- A button ignores a second tap while its own
asynchandler is at work. - Another button does not wait. Bind both to a state such as
page.state.busywhen they must not run together. - A handler that throws is caught in the same way as a hook.
The guide for this section is Event Handling Patterns.
The calls of every day#
The base class of our controllers keeps the page and the app in pageInitialized:
pageInitialized(page, app) {
this.page = page;
this.app = app;
}With these two, the lines below are most of what a controller does. Each call runs in our lab app, with these values or with others:
// a datasource of the page, or one of the application
const ds = this.page.findDatasource('fs_d_load_free');
const shared = this.app.findDatasource('fs_l_panels_ds');
// state: one page, or the whole app
this.page.state.busy = true;
this.app.state.ctlCount = (this.app.state.ctlCount || 0) + 1;
// go to another page, with values for it
this.app.setCurrentPage({name: 'fs_c_nav_list', params: {reload: true}});
// open a dialog of the page, and close it
this.page.showDialog('fs_k_dialog_prio');
this.page.findDialog('fs_k_dialog_prio').closeDialog();
// tell the user
this.app.toast('Saved', 'success');
this.app.toast(`Save failed: ${e.message}`, 'error');
// the event bus: keep the handler, so that off can name it
this.app.on('fs-clean', this.onClean);
this.app.off('fs-clean', this.onClean);
this.app.emit('fs-clean', {n: 1});| Store | Who reads it | Use it for |
|---|---|---|
page.state | the page and its controller | what one screen shows: a tab, a filter, a busy flag |
app.state | every page and every controller | what pages share: the picked record, a setting |
a field such as this.count | this one controller object | values that no markup binds to |
The guides for this section are Pages and Navigation, Understanding State Management, Datasource Cheatsheet.
Two patterns to copy#
A hook that can fail, with a message for the user, as the hooks guide prints it. The load is the line that may throw:
async pageResumed(page) {
try {
await page.findDatasource('fs_ctl_ds').load();
} catch (e) {
this.app.toast(`Loading failed: ${e.message}`, 'error');
}
}A subscription that is removed when the page leaves the screen:
pageResumed() {
this.app.on('fs-clean', this.onClean);
}
pagePaused() {
this.app.off('fs-clean', this.onClean);
}Without the off, the handler ran once more for every visit of the page.
This page as a PDF, to print or to keep beside the keyboard.
IBM documents the attribute controller and the event attributes in the product itself. In the Application Configuration application, open the ? menu and choose Component Documentation. The controller hooks are described in IBM’s developer documentation for the Maximo Application Framework.
