Codync
免费开源的 1:1 Grok Bot 与 Muse 替代方案。可在 iPhone、Mac 或 Linux 桌面上将 Claude 代码、Codex、Cursor 以及 40 多个编码代理作为持久机器人使用。支持群组聊天、线程、应用。
AI 翻译
尚未检测到更新。GitHub 发布版本后会显示在这里。
个人 GitHub 账号下公开仓库的所有者可以登录并验证所有权,自行管理介绍,无需管理员批准。
登录并生成验证文件,在 30 分钟内将其提交到此仓库的默认分支。其他分支或分叉仓库中的文件无效。然后在下方检查文件,即可无需管理员批准直接管理项目。请保留文件以维持管理权限。
如需登录,将前往登录页面。登录后请回到此处,再次点击所选的验证按钮。
在项目文件夹中运行 /nomorevibe verify,即可验证所有权并自行管理介绍。
一分钟完成验证制作者的介绍仅有上面的一句话。 更多详情请阅读仓库 README。 仓库 README ↗
正在加载完整 README。
查看完整 README ↗The classic low-level design interview question, solved without the State pattern: the whole machine is one pure function.
step(machine, event) → [machine, effects]
▶ Try it in the animated walkthrough: buy something, jam the motor, run out of change, then scrub back through time and branch from any moment.
stateDiagram-v2
[*] --> idle
idle --> paying: select (in stock)
paying --> paying: insert / buy before fully paid
paying --> dispensing: buy (paid ≥ price, change possible)
paying --> idle: cancel / no change possible
dispensing --> idle: dispensed (commit) / jammed (refund)
| File | Role |
|---|---|
src/machine.ts | Types and step(): every (phase, event) pair, nothing else. No I/O, no clock, no mutation |
src/coins.ts | Integer cents, coin counts, makeChange() |
tests/properties.test.ts | fast-check: thousands of random event sequences against invariants |
docs/index.html | The shell: renders the machine and replays events through the same core (docs/vending.js is built from src/) |
The textbook solution is a VendingMachine class holding selectedProduct, totalCoins and currentState, plus a State pattern with Idle, Ready, Dispense and ReturnChange classes that call machine.setState(new ...).
switch is fine when the compiler checks it. The OOP answer rejects switch on Open/Closed grounds. With discriminated unions and noImplicitReturns, dropping a case fails the build, which is stronger than OCP for a closed set of states.idle has none and paying has slot and inserted. "Idle with a product selected" cannot be written down.{ tag: 'returnCoins', coins } and not a ReturnChangeState. Tests read effects like any value, and the page animates them.dispensed. On jammed the exact inserted coins go back and nothing was ever written.totalCoins = 135 cannot tell you whether 35¢ of change is possible. The box keeps counts per denomination, and that is the only way "Exact change only" fits in the design.makeChange backtracks and is checked against brute force.step one at a time. If the machine sits behind an API, serialising events per machine is the shell's job, and the core does not change.run(start, events) on every render.Hand-written scenarios cover the obvious paths. The property tests generate random machines and up to 60 random events (coins while dispensing, sensor signals out of nowhere, slots that do not exist) and check, at every step:
box + inserted = box' + returned + escrowmakeChange finds change exactly when brute force says it existsTo check they are not decorative: drop the line that pays change out of the box and three tests fail. Drop any case and tsc refuses to compile.
Requires Node 23+.
npm install
npm test # unit + property tests
npm run typecheck
npm run build:web # rebuild docs/vending.js after changing src/
Open docs/index.html through any static server, for example npx serve docs.