Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
16 lines
483 B
JavaScript
16 lines
483 B
JavaScript
/**
|
|
* A counter whose count lives in the vat's storage.
|
|
*
|
|
* TODO: a durable Exo once vatPowers offers a zone, e.g.
|
|
* `zone.exoClass("Counter", undefined, () => ({ count: 0 }), { incr() { this.state.count += 1; return this.state.count; } })`
|
|
*/
|
|
export const buildRootObject = ({ Far, storage }) =>
|
|
Far("counterRoot", {
|
|
increment: () => {
|
|
const n = (storage.get("count") ?? 0) + 1;
|
|
storage.put("count", n);
|
|
return n;
|
|
},
|
|
read: () => storage.get("count") ?? 0,
|
|
});
|