Skip to content

Order history

A shop shows a signed-in customer their recent orders. The host’s order service answers with the list, and the micro-app renders one card per order. Each card can edit its order’s delivery note or remove the order, both through the host. Under it, a short list of delivery steps comes from the document’s own state.

  • Watch the first load: Loading orders… shows until the host answers, then one card per order.
  • Look at the delivered order: it has no status line, while the others do.
  • Look at each total: the host sends 89.9, and the card shows it as euros in your browser’s locale, such as €89.90.
  • Change Customer ID to cus_5520 and press Enter. Committing the field refetches with the new id, the host answers with an empty list, and the empty-state text appears instead of the cards. Change it back to cus_3107 to bring the orders back.
  • Press Track this order on a card. That order’s reference and status appear under the list; press it on another card and the other order replaces it.
  • Press Edit delivery note on a card, type a note, and press Save note. The card keeps its old note until the host answers, then shows the new one, and the editor closes. A note over 120 characters is refused before the host is asked, and the editor stays open.
  • Press Remove from history on a card and confirm. That order’s card goes, and the others stay.
  • Open Session state: each order holds only the declared fields, and /meta/objects/orders/count holds the number of rows, including after a removal.

orders is declared with cardinality: "many", so it is a list of records keyed by its id identity. Besides fetch it enables update, with a note input, and delete. Its design sample is an array:

{
"orders": {
"type": "shop.order",
"cardinality": "many",
"identity": "id",
"fields": {
"id": {
"kind": "string",
"required": true
},
"reference": {
"kind": "string",
"required": true
},
"placedOn": {
"kind": "string",
"required": true
},
"status": {
"kind": "string",
"required": true,
"enum": [
"processing",
"shipped",
"delivered"
]
},
"total": {
"kind": "number",
"required": true
},
"note": {
"kind": "string",
"nullable": true
}
},
"capabilities": {
"fetch": {
"inputs": {
"customerId": {
"kind": "string",
"required": true
}
}
},
"update": {
"inputs": {
"note": {
"kind": "string",
"nullable": true,
"maxLength": 120
}
}
},
"delete": {}
},
"sample": [
{
"id": "ord_sample_1",
"reference": "SO-0001",
"placedOn": "2 Sep 2026",
"status": "shipped",
"total": 120,
"note": "Leave with the neighbour"
},
{
"id": "ord_sample_2",
"reference": "SO-0002",
"placedOn": "28 Aug 2026",
"status": "delivered",
"total": 80
}
]
}
}

Startup fetches the orders of the customer whose id is in document state:

{
"lifecycle": {
"startup": [
{
"action": "fetch",
"params": {
"object": "orders",
"inputs": {
"customerId": {
"$state": "/customerId"
}
}
}
}
]
}
}

The Customer ID Input edits that same state path, and its commit runs the same fetch. commit fires every time the person presses Enter, and when they leave the field after changing it, never per keystroke. If they commit again while an earlier commit’s fetch is still loading, the newer fetch replaces it and only its answer lands. A commit while the startup fetch is still loading is rejected as busy; pressing Enter or leaving the field again retries it:

{
"customer-id": {
"type": "Input",
"props": {
"label": "Customer ID",
"placeholder": "cus_3107",
"inputType": "text",
"required": false,
"helpText": "Change it and press Enter, or leave the field, to load that customer's orders.",
"value": {
"$bindState": "/customerId"
}
},
"children": [],
"on": {
"commit": {
"action": "fetch",
"params": {
"object": "orders",
"inputs": {
"customerId": {
"$state": "/customerId"
}
}
}
}
}
}
}

The order-list Stack repeats over /objects/orders/data, keyed by the identity. Its only child is the card template, whose Texts read the row with $item, and the status line hides for delivered orders:

{
"order-list": {
"type": "Stack",
"props": {
"direction": "vertical",
"gap": "sm",
"align": "stretch",
"justify": "start",
"wrap": false,
"padding": "none",
"surface": null
},
"children": [
"order-card"
],
"repeat": {
"statePath": "/objects/orders/data",
"key": "id"
}
},
"order-reference": {
"type": "Heading",
"props": {
"content": {
"$item": "reference"
},
"level": "3",
"align": "left",
"accent": false
},
"children": []
},
"order-status": {
"type": "Text",
"props": {
"content": {
"$item": "status"
},
"size": "md",
"tone": "default",
"align": "left",
"italic": false
},
"children": [],
"visible": {
"$item": "status",
"neq": "delivered"
}
}
}

The host answers with each order’s total as a plain number, 89.9. The total Text shows it as money with $format, in the viewer’s locale, so the host sends no display field such as totalLabel:

{
"order-total": {
"type": "Text",
"props": {
"content": {
"$format": "currency",
"value": {
"$item": "total"
},
"currency": "EUR"
},
"size": "md",
"tone": "default",
"align": "left",
"italic": false
},
"children": []
}
}

Each card carries a Track this order Button. Its setState value is a record whose fields read the pressed row with $item, so the press copies that order into ordinary state at /tracking, which the Stack after the list shows:

{
"order-track": {
"type": "Button",
"props": {
"label": "Track this order",
"variant": "outline",
"size": "sm",
"disabled": false,
"fullWidth": false
},
"children": [],
"on": {
"press": {
"action": "setState",
"params": {
"statePath": "/tracking",
"value": {
"reference": {
"$item": "reference"
},
"status": {
"$item": "status"
}
}
}
}
}
},
"tracking": {
"type": "Stack",
"props": {
"direction": "horizontal",
"gap": "sm",
"align": "center",
"justify": "start",
"wrap": true,
"padding": "md",
"surface": "soft"
},
"children": [
"tracking-label",
"tracking-reference",
"tracking-status"
],
"visible": {
"$state": "/tracking/reference"
}
}
}

The host’s row is never edited in place. Edit delivery note copies the card’s order into ordinary state at /noteDraft, identity included, and the editor after the list shows while the draft holds an id. Save note updates the order the draft names with row, reading the note from the draft, then clears the draft. A rejected update stops the event, so the draft stays for another try:

{
"order-edit-note": {
"type": "Button",
"props": {
"label": "Edit delivery note",
"variant": "outline",
"size": "sm",
"disabled": false,
"fullWidth": false
},
"children": [],
"on": {
"press": {
"action": "setState",
"params": {
"statePath": "/noteDraft",
"value": {
"id": {
"$item": "id"
},
"reference": {
"$item": "reference"
},
"note": {
"$item": "note"
}
}
}
}
}
},
"note-save": {
"type": "Button",
"props": {
"label": "Save note",
"variant": "solid",
"size": "sm",
"disabled": false,
"fullWidth": false
},
"children": [],
"on": {
"press": [
{
"action": "update",
"params": {
"object": "orders",
"inputs": {
"note": {
"$state": "/noteDraft/note"
}
},
"row": {
"id": {
"$state": "/noteDraft/id"
}
}
}
},
{
"action": "setState",
"params": {
"statePath": "/noteDraft",
"value": {}
}
}
]
}
}
}

When the host answers, Mica replaces that row in the list by its identity. The list is not refetched.

Remove from history deletes the card’s own order: its row reads the pressed row’s identity with $item. Mica asks the confirmation first, and on success removes the row and updates the count in the same store write:

{
"order-remove": {
"type": "Button",
"props": {
"label": "Remove from history",
"variant": "outline",
"size": "sm",
"disabled": false,
"fullWidth": false
},
"children": [],
"on": {
"press": {
"action": "delete",
"params": {
"object": "orders",
"row": {
"id": {
"$item": "id"
}
},
"confirmation": "Remove this order from your history?"
}
}
}
}
}

Loading and error read the fetch’s phase. The empty text needs both a finished fetch and a row count of 0:

{
"empty": {
"type": "Text",
"props": {
"content": "No orders yet. Anything you buy shows up here.",
"size": "md",
"tone": "muted",
"align": "left",
"italic": false
},
"children": [],
"visible": [
{
"$state": "/meta/objects/orders/operations/fetch/phase",
"eq": "success"
},
{
"$state": "/meta/objects/orders/count",
"eq": 0
}
]
}
}

The delivery steps are ordinary document state, keyed by each step’s code. The Grid repeats over them, and each cell shows its position with $index, counting from 0:

{
"deliverySteps": [
{
"code": "placed",
"label": "We confirm your order by email."
},
{
"code": "packed",
"label": "The warehouse packs it within a day."
},
{
"code": "shipped",
"label": "The carrier delivers it in two to four days."
}
],
"steps": {
"type": "Grid",
"props": {
"columns": 3,
"gap": "md",
"padding": "none",
"minCellWidth": 180
},
"children": [
"step"
],
"repeat": {
"statePath": "/deliverySteps",
"key": "code"
}
},
"step-number": {
"type": "Text",
"props": {
"content": {
"$index": true
},
"size": "md",
"tone": "muted",
"align": "left",
"italic": false
},
"children": []
}
}

A local list has no row count, so its empty text inverts a read of the first row with "not": true. Empty deliverySteps in the State tab to see it:

{
"steps-empty": {
"type": "Text",
"props": {
"content": "No delivery steps yet.",
"size": "md",
"tone": "muted",
"align": "left",
"italic": false
},
"children": [],
"visible": {
"$state": "/deliverySteps/0",
"not": true
}
}
}

See Show a list for the rules behind each part, and Edit a host row for row writes.

Complete document — examples/documents/order-history.json
examples/documents/order-history.json
{
"envelopeVersion": 1,
"ui": {
"root": "app",
"elements": {
"app": {
"type": "PageStack",
"props": {
"name": "Order history"
},
"children": [
"page-orders"
]
},
"page-orders": {
"type": "Page",
"props": {
"title": "Orders",
"background": "mist"
},
"children": [
"heading",
"customer-id",
"loading",
"load-error",
"empty",
"order-list",
"note-editor",
"remove-error",
"tracking",
"steps-heading",
"steps",
"steps-empty"
]
},
"heading": {
"type": "Heading",
"props": {
"content": "Your orders",
"level": "1",
"align": "left",
"accent": true
},
"children": []
},
"loading": {
"type": "Text",
"props": {
"content": "Loading orders…",
"size": "md",
"tone": "muted",
"align": "left",
"italic": false
},
"children": [],
"visible": {
"$state": "/meta/objects/orders/operations/fetch/phase",
"eq": "loading"
}
},
"load-error": {
"type": "Text",
"props": {
"content": {
"$state": "/meta/objects/orders/operations/fetch/error/message"
},
"size": "md",
"tone": "accent",
"align": "left",
"italic": false
},
"children": [],
"visible": {
"$state": "/meta/objects/orders/operations/fetch/phase",
"eq": "error"
}
},
"empty": {
"type": "Text",
"props": {
"content": "No orders yet. Anything you buy shows up here.",
"size": "md",
"tone": "muted",
"align": "left",
"italic": false
},
"children": [],
"visible": [
{
"$state": "/meta/objects/orders/operations/fetch/phase",
"eq": "success"
},
{
"$state": "/meta/objects/orders/count",
"eq": 0
}
]
},
"order-list": {
"type": "Stack",
"props": {
"direction": "vertical",
"gap": "sm",
"align": "stretch",
"justify": "start",
"wrap": false,
"padding": "none",
"surface": null
},
"children": [
"order-card"
],
"repeat": {
"statePath": "/objects/orders/data",
"key": "id"
}
},
"order-card": {
"type": "Stack",
"props": {
"direction": "vertical",
"gap": "sm",
"align": "stretch",
"justify": "start",
"wrap": false,
"padding": "md",
"surface": "soft"
},
"children": [
"order-reference",
"order-placed",
"order-status",
"order-total",
"order-delivery-note",
"order-track",
"order-edit-note",
"order-remove"
]
},
"order-reference": {
"type": "Heading",
"props": {
"content": {
"$item": "reference"
},
"level": "3",
"align": "left",
"accent": false
},
"children": []
},
"order-placed": {
"type": "Text",
"props": {
"content": {
"$item": "placedOn"
},
"size": "md",
"tone": "muted",
"align": "left",
"italic": false
},
"children": []
},
"order-status": {
"type": "Text",
"props": {
"content": {
"$item": "status"
},
"size": "md",
"tone": "default",
"align": "left",
"italic": false
},
"children": [],
"visible": {
"$item": "status",
"neq": "delivered"
}
},
"order-total": {
"type": "Text",
"props": {
"content": {
"$format": "currency",
"value": {
"$item": "total"
},
"currency": "EUR"
},
"size": "md",
"tone": "default",
"align": "left",
"italic": false
},
"children": []
},
"order-track": {
"type": "Button",
"props": {
"label": "Track this order",
"variant": "outline",
"size": "sm",
"disabled": false,
"fullWidth": false
},
"children": [],
"on": {
"press": {
"action": "setState",
"params": {
"statePath": "/tracking",
"value": {
"reference": {
"$item": "reference"
},
"status": {
"$item": "status"
}
}
}
}
}
},
"tracking": {
"type": "Stack",
"props": {
"direction": "horizontal",
"gap": "sm",
"align": "center",
"justify": "start",
"wrap": true,
"padding": "md",
"surface": "soft"
},
"children": [
"tracking-label",
"tracking-reference",
"tracking-status"
],
"visible": {
"$state": "/tracking/reference"
}
},
"tracking-label": {
"type": "Text",
"props": {
"content": "Tracking",
"size": "md",
"tone": "muted",
"align": "left",
"italic": false
},
"children": []
},
"tracking-reference": {
"type": "Text",
"props": {
"content": {
"$state": "/tracking/reference"
},
"size": "md",
"tone": "default",
"align": "left",
"italic": false
},
"children": []
},
"tracking-status": {
"type": "Text",
"props": {
"content": {
"$state": "/tracking/status"
},
"size": "md",
"tone": "accent",
"align": "left",
"italic": false
},
"children": []
},
"customer-id": {
"type": "Input",
"props": {
"label": "Customer ID",
"placeholder": "cus_3107",
"inputType": "text",
"required": false,
"helpText": "Change it and press Enter, or leave the field, to load that customer's orders.",
"value": {
"$bindState": "/customerId"
}
},
"children": [],
"on": {
"commit": {
"action": "fetch",
"params": {
"object": "orders",
"inputs": {
"customerId": {
"$state": "/customerId"
}
}
}
}
}
},
"steps-heading": {
"type": "Heading",
"props": {
"content": "How delivery works",
"level": "2",
"align": "left",
"accent": false
},
"children": []
},
"steps": {
"type": "Grid",
"props": {
"columns": 3,
"gap": "md",
"padding": "none",
"minCellWidth": 180
},
"children": [
"step"
],
"repeat": {
"statePath": "/deliverySteps",
"key": "code"
}
},
"steps-empty": {
"type": "Text",
"props": {
"content": "No delivery steps yet.",
"size": "md",
"tone": "muted",
"align": "left",
"italic": false
},
"children": [],
"visible": {
"$state": "/deliverySteps/0",
"not": true
}
},
"step": {
"type": "Stack",
"props": {
"direction": "vertical",
"gap": "sm",
"align": "stretch",
"justify": "start",
"wrap": false,
"padding": "md",
"surface": "soft"
},
"children": [
"step-number",
"step-label"
]
},
"step-number": {
"type": "Text",
"props": {
"content": {
"$index": true
},
"size": "md",
"tone": "muted",
"align": "left",
"italic": false
},
"children": []
},
"step-label": {
"type": "Text",
"props": {
"content": {
"$item": "label"
},
"size": "md",
"tone": "default",
"align": "left",
"italic": false
},
"children": []
},
"order-delivery-note": {
"type": "Text",
"props": {
"content": {
"$item": "note"
},
"size": "md",
"tone": "muted",
"align": "left",
"italic": false
},
"children": [],
"visible": {
"$item": "note"
}
},
"order-edit-note": {
"type": "Button",
"props": {
"label": "Edit delivery note",
"variant": "outline",
"size": "sm",
"disabled": false,
"fullWidth": false
},
"children": [],
"on": {
"press": {
"action": "setState",
"params": {
"statePath": "/noteDraft",
"value": {
"id": {
"$item": "id"
},
"reference": {
"$item": "reference"
},
"note": {
"$item": "note"
}
}
}
}
}
},
"order-remove": {
"type": "Button",
"props": {
"label": "Remove from history",
"variant": "outline",
"size": "sm",
"disabled": false,
"fullWidth": false
},
"children": [],
"on": {
"press": {
"action": "delete",
"params": {
"object": "orders",
"row": {
"id": {
"$item": "id"
}
},
"confirmation": "Remove this order from your history?"
}
}
}
},
"note-editor": {
"type": "Stack",
"props": {
"direction": "vertical",
"gap": "sm",
"align": "stretch",
"justify": "start",
"wrap": false,
"padding": "md",
"surface": "soft"
},
"children": [
"note-heading",
"note-input",
"note-save",
"note-save-error"
],
"visible": {
"$state": "/noteDraft/id"
}
},
"note-heading": {
"type": "Text",
"props": {
"content": {
"$state": "/noteDraft/reference"
},
"size": "md",
"tone": "muted",
"align": "left",
"italic": false
},
"children": []
},
"note-input": {
"type": "Input",
"props": {
"label": "Delivery note",
"placeholder": "Leave with the neighbour",
"inputType": "text",
"lines": 3,
"required": false,
"helpText": "Saved to this order only when the shop answers.",
"value": {
"$bindState": "/noteDraft/note"
},
"error": {
"$state": "/meta/objects/orders/operations/update/error/fieldErrors/note"
}
},
"children": []
},
"note-save": {
"type": "Button",
"props": {
"label": "Save note",
"variant": "solid",
"size": "sm",
"disabled": false,
"fullWidth": false
},
"children": [],
"on": {
"press": [
{
"action": "update",
"params": {
"object": "orders",
"inputs": {
"note": {
"$state": "/noteDraft/note"
}
},
"row": {
"id": {
"$state": "/noteDraft/id"
}
}
}
},
{
"action": "setState",
"params": {
"statePath": "/noteDraft",
"value": {}
}
}
]
}
},
"note-save-error": {
"type": "Text",
"props": {
"content": {
"$state": "/meta/objects/orders/operations/update/error/message"
},
"size": "md",
"tone": "accent",
"align": "left",
"italic": false
},
"children": [],
"visible": {
"$state": "/meta/objects/orders/operations/update/phase",
"eq": "error"
}
},
"remove-error": {
"type": "Text",
"props": {
"content": {
"$state": "/meta/objects/orders/operations/delete/error/message"
},
"size": "md",
"tone": "accent",
"align": "left",
"italic": false
},
"children": [],
"visible": {
"$state": "/meta/objects/orders/operations/delete/phase",
"eq": "error"
}
}
},
"state": {
"customerId": "cus_3107",
"deliverySteps": [
{
"code": "placed",
"label": "We confirm your order by email."
},
{
"code": "packed",
"label": "The warehouse packs it within a day."
},
{
"code": "shipped",
"label": "The carrier delivers it in two to four days."
}
],
"noteDraft": {}
}
},
"meta": {
"pack": {
"id": "mica.core",
"version": "1.0.0"
}
},
"objects": {
"orders": {
"type": "shop.order",
"cardinality": "many",
"identity": "id",
"fields": {
"id": {
"kind": "string",
"required": true
},
"reference": {
"kind": "string",
"required": true
},
"placedOn": {
"kind": "string",
"required": true
},
"status": {
"kind": "string",
"required": true,
"enum": [
"processing",
"shipped",
"delivered"
]
},
"total": {
"kind": "number",
"required": true
},
"note": {
"kind": "string",
"nullable": true
}
},
"capabilities": {
"fetch": {
"inputs": {
"customerId": {
"kind": "string",
"required": true
}
}
},
"update": {
"inputs": {
"note": {
"kind": "string",
"nullable": true,
"maxLength": 120
}
}
},
"delete": {}
},
"sample": [
{
"id": "ord_sample_1",
"reference": "SO-0001",
"placedOn": "2 Sep 2026",
"status": "shipped",
"total": 120,
"note": "Leave with the neighbour"
},
{
"id": "ord_sample_2",
"reference": "SO-0002",
"placedOn": "28 Aug 2026",
"status": "delivered",
"total": 80
}
]
}
},
"lifecycle": {
"startup": [
{
"action": "fetch",
"params": {
"object": "orders",
"inputs": {
"customerId": {
"$state": "/customerId"
}
}
}
}
]
}
}