toJson method
includeActions is off for a renderer whose caller has another way to
read the declarations, and for whom carrying them is not free. It covers
description too, which is a declaration in the same sense — one static
sentence, the same on every project and in every reply.
Measured, not tidied. An action declaration is static — the same bytes
every time — and it dominates a report: on flutterware's own repo the
Previews report is 39k characters of JSON, 38k of it declarations. A
terminal pays nothing for that, so fw status --json keeps them. An agent
pays for every one of them in every reply, and already has a tool that
serves them on request.
viewRows caps every list and table in the projection, counting the rest
— see PluginView.capped. Null keeps the projection whole, which is what
a panel and a terminal want.
includeView drops the projection entirely, leaving what the sidebar
shows collapsed: the status line, the badge and the children. Measured on
this repo, the view is 90% of a status reply — 19.2k of 21.7k
characters — because it is the inventory, and an inventory is what each
plugin's own actions serve in full. A reader that wants to know which
plugins are unhappy is asking about the other 10%.
Implementation
Map<String, Object?> toJson({
bool includeActions = true,
bool includeView = true,
int? viewRows,
}) => {
'id': id,
'label': label,
if (includeActions && description != null) 'description': description,
'status': status.toJson(),
if (!badge.isEmpty) 'badge': badge.toJson(),
if (includeActions && actions.isNotEmpty)
'actions': [for (var a in actions) a.toJson()],
if (teardown.isNotEmpty) 'teardown': [for (var t in teardown) t.toJson()],
if (guards.isNotEmpty) 'guards': [for (var g in guards) g.toJson()],
if (children.isNotEmpty) 'children': [for (var c in children) c.toJson()],
if (includeView && !view.isEmpty)
'view': (viewRows == null ? view : view.capped(viewRows)).toJson(),
};