Skip to content

Instantly share code, notes, and snippets.

@dckc
Created December 28, 2019 23:43
Show Gist options
  • Save dckc/15291a3568cf5c5276278fe2929cfded to your computer and use it in GitHub Desktop.
Save dckc/15291a3568cf5c5276278fe2929cfded to your computer and use it in GitHub Desktop.
/* global Compartment, trace */
export default function main() {
let g1Value = 'g1 original value';
const g1Slot = {
get p1() {
trace(`getting g1: ${g1Value}\n`);
return g1Value;
},
set p1(v) {
trace(`setting g1: ${g1Value} -> ${v}\n`);
g1Value = v;
},
};
const c1 = new Compartment("mod", { g1Slot });
}
{
"include": "$(MODDABLE)/examples/manifest_base.json",
"modules": {
"*": [
"./main",
"./mod",
],
},
"preload": [
],
}
trace(globalThis.g1Slot.p1 + '\n');
globalThis.g1Slot.p1 = 'new value';
trace('mod done.\n');
@dckc
Copy link
Author

dckc commented Dec 28, 2019

LOG:

getting g1: g1 original value
g1 original value
setting g1: g1 original value -> new value
mod done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment