diff --git a/snippets/zoe/src/02b-state-durable.js b/snippets/zoe/src/02b-state-durable.js index 4dfdab10a..5a8dc1d09 100644 --- a/snippets/zoe/src/02b-state-durable.js +++ b/snippets/zoe/src/02b-state-durable.js @@ -1,31 +1,39 @@ // @ts-check -import { makeDurableZone } from '@agoric/zone/durable.js'; +// #region contract import { M } from '@endo/patterns'; +// #region import-provide-zone +import { makeDurableZone } from '@agoric/zone/durable.js'; +import { provide } from '@agoric/vat-data'; +// #endregion import-provide-zone + +// #region interface-guard +const CellI = M.interface('ValueCell', { + get: M.call().returns(M.number()), + set: M.call(M.number()).returns(), +}); +// #endregion interface-guard -export const start = (_zcf, _privateArgs, baggage) => { - /** @type {import('@agoric/zone').Zone} */ +// #region export-prepare +export const prepare = (_zcf, _privateArgs, baggage) => { + // #endregion export-prepare + // #region exo const zone = makeDurableZone(baggage); - const makeCell = zone.exoClass( - 'Cell', - M.interface('Cell', { - get: M.call().returns(M.scalar()), - set: M.call(M.scalar()).returns(), - }), - () => ({ - /** @type {string|number} */ - value: 'Hello, World!', - }), - { - get() { - return this.state.value; - }, - /** @param {string|number} v */ - set(v) { - this.state.value = v; - }, + const makeCell = zone.exoClass('ValueCell', CellI, () => ({ value: 0 }), { + get() { + return this.state.value; }, - ); - const publicFacet = makeCell(); + /** @param {number} v */ + set(v) { + this.state.value = v; + }, + }); + // #endregion exo + + // #region provide-cell + const publicFacet = provide(baggage, 'publicFacet', makeCell); + return { publicFacet }; + // #endregion provide-cell }; +// #endregion contract