---
title: Stato e aspetto del nodo
project: Total.js Flow
version: 11.1
section: development
language: it
license: MIT
url: https://totaljs.es/docs/it/flow/11-1/development/status-and-look/
updated: 2026-11-19T10:58:54.144Z
---

# Stato e aspetto del nodo

> Mostra informazioni in tempo reale sul nodo con uno stato, progetta il suo corpo e aggiungi uno script che gira nel designer.

Un nodo può mostrare informazioni in tempo reale sul canvas: un contatore, l'ultimo valore, lo stato di una connessione. Il codice del server invia uno stato, e il `<body>` del componente lo mostra.

Questa pagina costruisce **Tally**, che conta i messaggi che riceve e colora il numero di rosso a partire da un limite impostato nelle sue impostazioni.

![Un nodo Tally che ha contato 12 messaggi, con un pulsante Reset](/files/JapyXN6zE60f.webp)

## Inviare uno stato

`instance.status(data)` invia qualsiasi dato ai designer che hanno il FlowStream aperto:

```js
var status = { count: 0 };

instance.message = function($) {
	status.count++;
	instance.status(status, 500);
	$.destroy();
};

instance.status(status);
```

Con un secondo argomento, Flow aspetta quel numero di millisecondi e poi invia l'ultimo stato. Un nodo che riceve molti messaggi invia così un solo stato invece di uno per ogni messaggio: dodici messaggi rapidi a **Tally** arrivano nel designer come un unico stato con `count` `12`.

Flow conserva l'ultimo stato di ogni nodo e lo invia di nuovo quando qualcuno apre il designer.

## Mostrare lo stato nel corpo

`$STATUS` in `<body>` è l'ultimo stato del nodo. Collegalo con `ui-bind`:

```html
<body>
	<header>
		<i class="$ICON"></i>$NAME
	</header>
	<footer>
		<ui-bind path="$STATUS" config="text:value && value.count ? value.count : '0'" class="count block"></ui-bind>
		<button name="trigger">Reset</button>
	</footer>
</body>
```

L'`<header>` con l'icona e il nome è la barra del titolo del nodo. Un `<button name="trigger">` chiama `instance.trigger` sul server, vedi [Trigger, timer e chiusura](../triggers-and-timers/).

Dai stile al corpo in `<style>` con `.CLASS`, che vale solo per i nodi di questo componente:

```html
<style>
	.CLASS footer { padding: 10px; text-align: center; }
	.CLASS .count { font-size: 30px; font-weight: bold; }
	.CLASS .over { color: #E73323; }
	.CLASS button { width: 100%; margin-top: 5px; }
</style>
```

## Uno script nel designer

Uno `<script>` senza `total` gira nel browser, nel designer. `TOUCH` ti dà un oggetto per ogni nodo del componente:

```html
<script>
	TOUCH(function(exports, reinit) {
		exports.status = function(status, isinit) {
			exports.element.find('.count').tclass('over', !!status && status.count >= exports.config.limit);
		};
	});
</script>
```

| Nome | Cos'è |
|---|---|
| `exports.id` | L'id del nodo. |
| `exports.config` | La configurazione del nodo. |
| `exports.element` | L'elemento del nodo, come oggetto jQuery. |
| `exports.status = function(status, isinit)` | Chiamata quando arriva un nuovo stato. |
| `exports.configure = function(config, isinit)` | Chiamata quando la configurazione cambia. |
| `exports.click = function(el)` | Chiamata quando l'utente fa clic su un `button` o su un elemento con la classe `clickable` nel nodo. |
| `exports.trigger(data)` | Chiama `instance.trigger` sul server con `data`. |
| `exports.call(data, callback)` | Chiama `instance.call` sul server e riceve la sua risposta. |

`reinit` è `true` quando il componente è cambiato e il designer esegue di nuovo lo script.

## Mostrare l'avanzamento

Per un lavoro lungo, `instance.activity(key, name, progress)` aggiunge una riga ad **Activities** (Attività) nella barra degli strumenti del designer:

```js
instance.activity('import', 'Importing orders', 50);   // 50 %
instance.activity('import', 'Importing orders', 100);  // done, the line disappears
```

## Il componente completo

```html
<script total>

	exports.id = 'tally';
	exports.name = 'Tally';
	exports.icon = 'ti ti-calculator';
	exports.author = 'Jane Doe';
	exports.version = '1';
	exports.group = 'Demo';
	exports.config = { limit: 10 };
	exports.inputs = [{ id: 'input', name: 'Input' }];

	exports.make = function(instance, config) {

		var status = { count: 0 };

		instance.message = function($) {
			status.count++;
			instance.status(status, 500);
			$.destroy();
		};

		instance.trigger = function() {
			status.count = 0;
			instance.status(status);
		};

		instance.status(status);
	};

</script>

<style>
	.CLASS footer { padding: 10px; text-align: center; }
	.CLASS .count { font-size: 30px; font-weight: bold; }
	.CLASS .over { color: #E73323; }
	.CLASS button { width: 100%; margin-top: 5px; }
</style>

<readme>
Counts the incoming messages. Select **Reset** to start again from zero.
</readme>

<settings>
	<div class="padding">
		<ui-component name="input" path="?.limit" config="type:number;min:1" class="m">Highlight from</ui-component>
	</div>
</settings>

<body>
	<header>
		<i class="$ICON"></i>$NAME
	</header>
	<footer>
		<ui-bind path="$STATUS" config="text:value && value.count ? value.count : '0'" class="count block"></ui-bind>
		<button name="trigger">Reset</button>
	</footer>
</body>

<script>
	TOUCH(function(exports, reinit) {
		exports.status = function(status, isinit) {
			exports.element.find('.count').tclass('over', !!status && status.count >= exports.config.limit);
		};
	});
</script>
```
