Store: One Root, Private Memory
Chapters
- Give the Shop its root
- Open branch nine
- Follow the attachment to private data
Transcript
Give the Shop its root
The Shop installer creates a memory cell for the root. Its own data is empty. The lower compartment holds attachments to child memories. The installer fills those slots before Store installs the root. The installer attaches Branches to the branches slot, then Settings to the settings slot. Each Child Slot holds at most one child. Store installs the assembled tree as the actor root. Branches can now attach an inventory for each branch number in its Child Map.
Open branch nine
Open branch nine. Branches checks for that key in its child map and checks that it has room for another branch. Nine is free here. The method asks Inventory to create the memory for that branch inside the current write scope. Inventory uses its private memory key to create a cell with an empty item map. The constructor returns a Detached ticket. Branches can attach that ticket in this write scope. Branches attaches the inventory at key nine. Attaching consumes the ticket. That entry owns the inventory now. If Branches later takes the attachment out, the child comes back as a Detached ticket. A child left detached retires when the scope finishes.
Follow the attachment to private data
Inside the inventory, the item map will use a product number to find an item. The child map uses a branch number to find the inventory itself. Inventory holds the private key it will need to read or write its data. Branches owns the attachment. Its edge ends at the memory boundary. Follow the owning edges back from inventory nine, through Branches, to the actor's root. Settings reaches that same root through its own slot. The next checkout will use this inventory for stock and Settings for tax.