A screen with no request in it
Business screens typically send requests to one gateway with a service name and receive responses wrapped in a fixed envelope format. In this screen, that handling is in a shared component, and the screen's code contains only the service name and the payload.
Screen >> login =
(rpc call: 'SA001LoginService' with: self credentials) forced
ifPresent: [:j |
Kept at: 'token' put: ((j at: 'access_token') asStr orElse: ['']).
self with: { answer: ((j at: 'userName') asStr orElse: ['']) , ' さん、こんにちは' }]
ifAbsent: [self].
Http, the URL, the token, and the server's error list do not appear in this screen's code. A test verifies that they do not appear in the generated JavaScript either.
The result is a Maybe
rpc call:with: returns a Maybe[Json]. It contains a value only when the server reported success. Every other case is handled inside the component.
| Server response | Component's action |
|---|---|
success | Return the response body |
error | Show the error messages in the error region; return none |
fatal | Same, then navigate to the login page |
| Unrecognized format | Show a message in the error region |
| HTTP status not 2xx | Show the status in the error region |
| Status 0 (connection failed) | Same as fatal |
ifAbsent: says what the state is when there is no result. It is not error handling.
forced is written in the screen
A method that waits for a request returns a Future, so forced appears in the screen's code. Hiding it in the component would hide the order in which messages that arrive during the wait are processed.
Elements the page must provide
The overlay and the error region are mounted by the component, so they do not appear in the screen's code. The page provides two container elements. The error region goes at the top of the page; the overlay's position is set by CSS.
Both must be outside the screen actor's region. An actor redraws its whole region, so an element placed inside it is removed on the next redraw.