Messages
Messages for the user, which the message displays of react-cad and Buerligons show: to tell what an app is doing.
Functions
showMessage()
function showMessage(message): string;
Tells the user something: shows a message in the message display of react-cad and Buerligons.
The store holds one message, the latest (message of BuerliState): a new one takes the place of the one
before, and the display, which keeps a list of them, shows it as it comes. Warnings and errors of ClassCAD calls
come this way as well.
Parameters
| Parameter | Type | Description |
|---|---|---|
message | Message | What to say, and what kind of message it is. |
Returns
string
The message's id, for updateMessage and closeMessage.
Example
import { createApi } from '@buerli.io/classcad'
import { closeMessage, showMessage, updateMessage } from '@buerli.io/core'
const id = showMessage({ type: 'busy', text: 'Recalculating …', drawingId })
try {
await createApi(drawingId).v1.common.recalc()
updateMessage(id, { type: 'success', text: 'Recalculated', drawingId })
} catch {
// ClassCAD's error comes as a message of its own
closeMessage(id)
}
closeMessage()
function closeMessage(id): void;
Takes a message back: clears the store's latest message if it is this one.
A display of the latest message, like Buerligons' one-line message, clears with it; react-cad's list keeps the messages it has shown. showMessage has an example.
Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | The message, as showMessage returned it. |
Returns
void
updateMessage()
function updateMessage(id, message): void;
Replaces a message that showMessage showed, for example a busy message with its outcome.
The replacement becomes the store's latest message, with the same id, also when other messages came since. showMessage has an example.
Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | The message, as showMessage returned it. |
message | Message | What the message says now. |
Returns
void
Types
Message
type Message = {
code?: number;
drawingId?: DrawingID;
duration?: number;
scope?: string | number;
source?: "client" | "server";
text: string;
title?: string;
type?: "error" | "success" | "info" | "warning" | "busy";
};
A message for the user, as showMessage shows it.
showMessage has an example.
Properties
| Property | Type | Description |
|---|---|---|
code? | number | A code, such as the error code of ClassCAD's message. |
drawingId? | DrawingID | The drawing the message is about. |
duration? | number | How long a display shows the message, in seconds; 0 keeps it until it is closed. The store does not act on it, and react-cad's display has times of its own. |
scope? | string | number | What the message belongs to, for a display that tells messages apart by it. |
source? | "client" | "server" | Where the message comes from: the app ('client') or the server ('server'). |
text | string | What the message says. |
title? | string | A lead, which react-cad shows before the text in bold. A message of a ClassCAD call has the call's name. |
type? | "error" | "success" | "info" | "warning" | "busy" | The kind of message: 'error', 'warning', 'success', 'info', or 'busy' for work under way. A display marks and colors a message by it; react-cad keeps an error until it has been seen. |