Crew Cards: Owners Inside an Actor

Design problem and decision

  • Design problem The school actor holds five kinds of fact. Enrolling and scoring each touch several of them, and they must agree after every call.
  • Architect's decision Which module owns each fact, which module is a reducer behind a chain, which service coordinates, and what must the coordinator put into an action?
  • Outcome The viewer can write an owner table for an actor, choose between a plain module and a reducer, and specify a multi-module operation as: read through selectors, build one action, dispatch once.
  • Starting point Lesson 1 left the ActorMap with five small capsules in the school.
  • Handoff Lesson 3 decides who may reach these operations from outside.
  • Pacing Three and a half minutes.

Worked design

Crew Cards is illustrative. School state at 08:00:

Module Kind Saved state
Settings plain memory pass mark 70
Courses plain memory 12: tov, carded. 15: tov, uncarded.
Students plain memory 340 mira, 341 ode, 342 pau, 343 kit, 344 sol
Roll reducer on the roll chain 340·12 Passed{82}, 341·12 NotPassed{55}, 342·15 Passed{90}, 343·12 Passed{74}. open awards 0. Chain tip 115.
Office saves nothing —

The owner table:

Fact Owner Read by Change requested by
pass mark Settings Office dean
course, instructor, carded Courses Office, award workflow dean
student and principal Students Office dean
enrollment and status Roll Office, award workflow, queries Office, award workflow, by dispatch only

The two operations of this film:

Time Call Action dispatched Reply State after
08:30 sol · enroll(12) Enroll(344, 12) Enrolled 344·12 Enrolled. Block 116.
08:40 tov · record_score(344, 12, 91) Score(344, 12, 91, 70) Scored{passed} 344·12 Passed{91}. Block 117.

Score carries the pass mark that was in force. The roll reducer compares 91 with the 70 in the action.

The story in one pass

Enlarge the five capsules. Fill the owner table. Decide that the roll is a reducer and the other three are plain modules. Add Office, which saves nothing. Send an enrollment through: three reads, one action, one dispatch. Send a score through and stop at the moment Office writes the pass mark into the action.

Views and visual objects

Use the shared visual language. This film introduces OwnerTable and places the canonical Rechain machine inside the school.

View Framing and anchor
school The school canister fills the frame. Settings, Courses and Students in a row across the top. Office at middle left. The dotted Rechain boundary across the bottom, holding dispatch, one enlarged roll reducer and the chain. The right third is reserved for the award workflow and stays empty in this film.
sheet The OwnerTable over the left third, with school dimmed behind it.

Scene owners — One owner for each fact

Already on screen The ActorMap from lesson 1.

Beat enter_school — Inside the school

View and focus map to school.

Narration

Go inside the school. Five facts came in. Enrollment and score are two sides of one record, so they share a module, the roll. That leaves four: settings, courses, students and the roll. Each module is the only code that touches its memory.

Cue and animation On “Go inside”, the camera moves into the school. On “share a module”, the enrollment and score capsules merge into one labeled roll. On each of the four names, its capsule grows to readable size and opens its vault to show the 08:00 values. The roll draws as a plain capsule for now.

Leaves with Four capsules with open vaults. The registry is out of frame.

Beat owner_table — The table an architect writes

View and focus sheet.

Narration

Write it as a table. The fact. Its owner. Who reads it. Who may ask for it to change. One owner per row. If two modules both want to write the same fact, the design is not finished.

Cue and animation On “a table”, the OwnerTable slides in with four column headers. On “One owner per row”, the four rows fill, each with a thin leader to its capsule. On “not finished”, the owner column pulses once.

Leaves with The OwnerTable with four rows.

Beat which_is_reducer — Plain module or reducer

View and focus school. Focus on the roll.

Show The file tree, small at lower left, with roll/ open to show mod.rs, selectors.rs and memory/.

Narration

Three of these are plain modules. The dean changes a setting and it is changed. The roll is different. An enrollment or a score is a decision someone may question later, so every accepted change to the roll goes through Rechain. The roll becomes a reducer. It still owns its memory. It gains two things: changes arrive only as actions through dispatch, and everyone else reads it through selectors.

Cue and animation On “The roll is different”, the roll capsule moves down and the dotted Rechain boundary draws around it with the canonical dispatch and the chain row, tip 115. The capsule redraws as the canonical enlarged reducer with its state folder and a badge selector status. On “only as actions through dispatch”, the fork from dispatch to the reducer draws. On “through selectors”, selectors.rs highlights in the tree and the selector badge pulses.

Leaves with Three plain capsules on top, the Rechain machine with one roll reducer below, chain tip 115.

Beat office — The one that saves nothing

View and focus school. Focus on Office.

Narration

Enrolling needs students, courses and the roll at once. So we add Office. Office has functions and no memory. It reads the others and dispatches to the roll. It sits in the place the Rechain film called the thunk.

Cue and animation On “we add Office”, a capsule with rim enroll, record_score, request_card and no vault draws at middle left, at the mouth of the Rechain input slot. On “reads the others”, thin CallLines draw from Office to Settings, Courses, Students and to selector status. On “dispatches to the roll”, a solid line draws from Office into dispatch.

Leaves with The school's call graph: four read lines and one dispatch line.

Scene enroll — Read, build, dispatch

Already on screen The school view with the call graph.

Beat enroll_reads — Three reads

View and focus school. Focus on Office.

Narration

Sol enrolls in course twelve. Office asks three questions. Students: is this caller a student? Yes, three-four-four. Courses: is there a course twelve? Yes. The roll's selector: is three-four-four already on course twelve? No.

Cue and animation On “Sol enrolls”, the pill enroll(12) arrives from the left rim and docks at Office inside a thin write Frame. On “Students”, a small pill travels to Students and returns 344. On “Courses”, one returns 12 ✓. On “The roll's selector”, one travels to selector status and returns none.

Leaves with Three answers beside Office. No value has changed.

Beat enroll_dispatch — One action, one block

View and focus school. Focus on the Rechain machine.

Narration

Office builds one action and dispatches it. The roll reducer checks the action against its own state and accepts. Its prepared change lands, and the chain gains block one-sixteen. Sol is enrolled.

Cue and animation On “builds one action”, the action pill Enroll(344, 12) forms at Office and enters dispatch. On “accepts”, a prepared commit tile leaves the reducer into the small row beneath. On “lands”, a new row 344·12 Enrolled descends into the roll's state folder. On “block one-sixteen”, the chain slides left one position, holds an empty spot, and block 116 Enroll(344, 12) forges and links. The OutcomeCard Enrolled leaves by the left rim. The frame closes.

Leaves with Roll shows 344·12 Enrolled. Chain tip 116.

Scene score — What the action must carry

Already on screen The school view, chain tip 116.

Beat score_reads — Instructor and pass mark

View and focus school. Focus on Office.

Narration

Ten minutes later Tov records Sol's score, ninety-one. Office asks Courses who teaches course twelve. It is Tov. Office asks Settings for the pass mark. Seventy.

Cue and animation On “Tov records”, the pill record_score(344, 12, 91) docks at Office in a new write frame. On “who teaches”, a pill returns tov ✓ from Courses. On “the pass mark”, a pill returns 70 from Settings and stays beside Office.

Leaves with tov ✓ and 70 beside Office.

Beat carry_the_mark — The reducer sees only its own

View and focus school. Focus on the action pill forming at Office.

Narration

Here is the design decision. A reducer checks an action against its own state and nothing else. The roll cannot look inside Settings. So Office writes the pass mark into the action.

Cue and animation On “its own state and nothing else”, the roll reducer's boundary brightens and a faint barrier shows between it and Settings. On “writes the pass mark into the action”, the pill forms as Score(344, 12, 91 and the 70 slides from beside Office into it, completing Score(344, 12, 91, 70).

Hold PauseAndExplain pointing at the 70 in the pill. The balloon reads:

What the action carries
  everything the reducer needs to decide
  everything a later reader needs to check it
The pass mark may change tomorrow.
This score was judged against 70.

Leaves with The complete pill Score(344, 12, 91, 70) at the mouth of dispatch.

Beat score_dispatch — Accepted and recorded

View and focus school. Focus on the Rechain machine.

Narration

Dispatch. The roll finds Sol enrolled and not yet scored, compares ninety-one with seventy, and accepts. Sol has passed. Block one-seventeen records it, pass mark included.

Cue and animation On “Dispatch”, the pill enters dispatch and travels the fork. On “accepts”, a prepared commit tile queues. On “Sol has passed”, the row changes from Enrolled to Passed{91}. On “Block one-seventeen”, the chain slides, holds, and forges 117 Score(344, 12, 91, 70). The OutcomeCard Scored{passed} leaves. The frame closes.

Leaves with Roll shows 344·12 Passed{91}. Chain tip 117. Lesson 3 starts from this state.

Brief to hand over

Illustrative.

Modules of school. Settings, Courses and Students are plain modules, changed only by controller methods. Roll is a reducer on the roll chain. It owns every enrollment and its status. All changes to it are dispatched actions. Everything else reads it through roll/selectors.rs.

Office. Saves nothing. Each operation reads what it needs through public functions and selectors, builds one action and dispatches once. Score carries the pass mark in force.

Roll rules. Enroll: not already on that course. Score: status is Enrolled, score is 0 to 100, result is Passed when score is at least the carried pass mark and NotPassed otherwise.

Acceptance checks, expected and not run

Given Command Expect Then
08:00 state sol · enroll(12) Enrolled 344·12 Enrolled, block 116
after that sol · enroll(12) Refused(AlreadyEnrolled) no value changed, tip stays 116
after that tov · record_score(344, 12, 91) Scored{passed} 344·12 Passed{91}, block 117 Score(344, 12, 91, 70)
after that tov · record_score(344, 12, 60) Refused(AlreadyScored) no value changed, tip stays 117
08:00 state sol · enroll(99) Refused(NoSuchCourse) no value changed
pass mark changed to 95 after block 117 read 344·12 Passed{91} unchanged, because the score was judged against the 70 in its block

After every row: the roll has at most one entry per student and course, and every refusal leaves the chain tip where it was.

Production and source notes

  • Crew Cards and its modules are illustrative. The split into plain modules and one reducer is this course's teaching design.
  • Plain modules beside a reducer under one root, with one shared Rechain runtime: Chat fixture README, lines 3 to 11. The chat fixture is evidence only.
  • A coordinating service that reads selectors, builds an action and dispatches: Basic Rechain commands. "Endpoints use commands and read-only selectors; they cannot call commit callbacks or access another reducer's mutable state." Basic Rechain fixture, lines 6 to 11.
  • A reducer prepares from its own memory, the action and fixed configuration, and has no write access while preparing: Rechain reducer traits, the Prepare and Commit traits. The Motoko guide states the same rule: Takt guide, lines 590 to 593.
  • A rejection consumes no block: Basic Rechain fixture, lines 20 to 21.
  • The recorded payload must hold what replay needs: Rechain README, lines 22 to 29. This is why the pass mark rides in the action.
  • Office occupies the canonical thunk slot of the Rechain drawing. In cdk-rsx the checked examples call this a commands service. Show the moving request with its full call, such as record_score(344, 12, 91).
  • In cdk-rsx a reducer returns a plan from prepare, and dispatch runs commit with it. Draw the plan as the canonical prepared commit tile. Do not name traits or tokens on screen.
  • The roll's state folder shows the current student's row and open awards 0. The other rows stay in the model. Use the same two-leaf folder at every scale.
  • The barrier in carry_the_mark is a faint line for one beat. It is not a new component.