-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
570793d
commit 63e0b89
Showing
2 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Zones | ||
|
||
Each Zone provides an API that allows the allocation of Exo objects and Stores | ||
(object collections) which use the same underlying persistence mechanism. This | ||
allows library code to be agnostic to whether its objects are backed purely by | ||
the JS heap (ephemeral), pageable out to disk (virtual) or can be revived after | ||
a vat upgrade (durable). | ||
|
||
See (SwingSet vat upgrade documentation)[../SwingSet/docs/vat-upgrade.md] for more details around the use of the zone API. | ||
|
||
An example of making a Zone-aware vat might look something like this: | ||
|
||
```js | ||
import { makeDurableZone } from '@agoric/zone/durable.js'; | ||
import { zoneFrobulator } from 'frob-package'; | ||
import { zoneWidget } from 'widget-package'; | ||
|
||
export const buildRootObject = (vatPowers, _args, baggage) => { | ||
const zone = makeDurableZone(baggage); | ||
|
||
// Ensure that Widgets cannot interfere with Frobs. | ||
const makeWidget = zoneWidget(zone.subZone('Widgets')); | ||
|
||
// Create a collection of frobulators. | ||
const frobZone = zone.subZone('Frobs'); | ||
const makeFrobulator = zoneFrobulator(frobZone); | ||
const widgetToFrob = frobZone.mapStore('widgetToFrob'); | ||
|
||
return Far('WidgetFrobulator', { | ||
makeWidget, | ||
registerWidget(w) { | ||
const frobulator = makeFrobulator(); | ||
widgetToFrob.init(w, frobulator); | ||
}, | ||
frobWidget(w) { | ||
const frobulator = widgetToFrob.get(w); | ||
return frobulator.frob(w); | ||
}, | ||
}); | ||
} | ||
``` |