A single, self-contained HTML file (a shareable demo) that lets anyone drive a state model by clicking buttons. Use this when the question is about business logic, state transitions, or data shape: the kind of thing that looks reasonable on paper but only feels wrong once you push it through real cases.
單一、自足的 HTML 檔案——一個可分享的示範——讓任何人透過點擊按鈕來操作狀態模型。當問題涉及商業邏輯、狀態轉換或資料形狀時使用——這類東西在紙上看起來合理,但要實際推演過真實案例才會覺得不對勁。
Because it's one file with nothing to install, you can hand it to a non-developer (a designer, a PM, a domain expert) and let them feel the model for themselves. So it speaks their language, not the code's.
因為它是單一檔案、無需安裝,你可以交給非開發者——設計師、PM、領域專家——讓他們親身體驗這個模型。所以它要講他們的語言,而不是程式的語言。
If the question is "what should this look like," this is the wrong branch. Use UI.md.
如果問題是「這個東西應該長什麼樣子」——錯的分支。改用 UI.md。
Before writing code, write down what state model and what question you're prototyping. One paragraph, at the top of the demo (in a visible intro, not just a comment). A logic prototype that answers the wrong question is pure waste, so make the question explicit so it can be checked later, whether the user is watching now or returning to it AFK.
寫程式之前,先寫下你正在製作原型的是什麼狀態模型、什麼問題。一段文字,放在示範頂端(放在可見的介紹裡,不只是註解)。回答了錯誤問題的邏輯原型是純粹的浪費——把問題寫明確,之後才能被檢驗,無論使用者現在在旁邊看,還是以後 AFK 回來。
Put the actual logic (the bit that's answering the question) in a single <script> block written as a small, pure module that could be lifted out and dropped into the real codebase later. The page around it is throwaway; this module isn't.
把真正的邏輯——回答問題的那部分——放在單一 <script> 區塊中,寫成一個小而純粹的模組,之後可以抽出來直接放進正式程式庫。頁面是拋棄式的;這個模組不是。
The right shape depends on the question:
正確的形狀取決於問題:
(state, action) => state. Good when actions are discrete events and state is a single value.(state, action) => state。當動作是離散事件、狀態是單一值時很適合。Pick whichever shape best fits the question being asked, not whichever is easiest to wire to a page. Keep it pure: no DOM, no document, no button handlers reaching inside it. The page calls into it; nothing flows the other direction. This is what makes the prototype useful past its own lifetime: once the question's answered, the validated reducer / machine / function set lifts into the real module on its own.
選擇最符合所問問題的形狀,而不是最容易接到頁面上的形狀。保持純粹:沒有 DOM、沒有 document、沒有伸進去的按鈕處理器。頁面呼叫它;沒有任何東西反向流動。這就是讓原型在自身壽命結束後仍然有用的原因:一旦問題得到解答,通過驗證的 reducer / 機器 / 函式集合就自行提升到正式模組中。
One file, plain HTML/CSS/JS: no framework, no bundler, no server, everything inline so it opens by double-click and survives being emailed around. Anyone should be able to run it by opening it.
單一檔案、純 HTML/CSS/JS——沒有框架、沒有打包器、沒有伺服器,全部內嵌,所以雙擊就能開啟、被轉寄也能存活。任何人都應該能開啟就跑。
Write it for a non-developer. Every label is in domain language, not code: buttons and state read like the business, not the reducer. Explain in plain words what's happening.
為非開發者而寫。每個標籤都用領域語言,不是程式碼——按鈕和狀態讀起來像商業本身,而不是 reducer。用白話解釋正在發生什麼。
Lay it out with a clean hierarchy, top to bottom:
用乾淨的階層由上而下排版:
Choose scenarios that demonstrate the awkward cases, the ones hard to reason about on paper: the happy path, a tricky edge case, an attempt at something that should be illegal.
選擇能示範棘手案例的情境——快樂路徑、棘手的邊緣案例、嘗試做某件應該是非法的動作——那些在紙上難以推演的案例。
Keep it beautiful but restrained: clean typography, generous spacing, one accent colour. No animations, no gimmicks: nothing that competes with the state and the buttons.
保持優美但克制:乾淨的排版、充裕的留白、一個主色。沒有動畫、沒有花招——沒有什麼會與狀態和按鈕搶目光。
Send them the file, or open it for them. They'll click through the walkthroughs and free-play whenever they get to it; the interesting moments are when they say "wait, that shouldn't be possible" or "huh, I assumed X would be different"; those are the bugs in the idea, which is the whole point. If they want new actions or a new scenario, add them. Prototypes evolve.
把檔案寄給對方,或幫他們開啟。他們有空時就會點擊引導示範和自由遊玩;有趣的時刻是當他們說「等等,那不應該可能發生」或「咦,我以為 X 會不一樣」——那些就是_想法_裡的 bug,而這正是重點。如果他們想要新動作或新情境,就加進去。原型會演化。
Once the prototype has answered its question, capture the answer, then capture the prototype the way the SKILL describes. The logic-specific mapping: the validated reducer / machine / function set lifts into the real module (the decision, absorbed); the HTML shell rides along to the throwaway branch that keeps the prototype as a primary source, and being one self-contained file, it stays trivially re-runnable there.
一旦原型回答了它的問題,先留存答案,再依照 SKILL 描述的方式留存原型。邏輯專屬的對應:通過驗證的 reducer / 機器 / 函式集合提升到正式模組(決策,已被吸收);HTML 外殼跟著送到把原型保留為主要來源的一次性分支——由於是單一自足的檔案,在那裡它依然可以輕鬆重跑。
document, or button handlers, it's no longer liftable. Keep the page as a thin shell over a pure module.document 或按鈕處理器,它就不再可提升。讓頁面保持為純模組之上的薄殼。