Skip to content

Commit

Permalink
chore: more concise durable example
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Feb 8, 2024
1 parent def7c2c commit bbd8169
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions snippets/zoe/src/02b-state-durable.js
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit bbd8169

Please sign in to comment.