Skip to content

Commit

Permalink
fix(exo): remove receiveRevoker (#1964)
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Jan 16, 2024
1 parent 03074ce commit d848754
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 184 deletions.
48 changes: 3 additions & 45 deletions packages/exo/src/exo-makers.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,6 @@ export const initEmpty = () => emptyRecord;
* @typedef {(power: P) => void} ReceivePower
*/

/**
* The power to revoke a live instance of the associated exo class, or the
* power to revoke a live facet instance of the associated exo class kit.
* If called with such a live instance, it revokes it and returns true. Once
* revoked, it is no longer live, and calling any of its methods throw
* an informative diagnostic with no further effects.
*
* @callback Revoke
* @param {any} exo
* @returns {boolean}
*/

/**
* The power to amplify a live facet instance of the associated exo class kit
* into the record of all facets of this facet instance's cohort.
Expand Down Expand Up @@ -136,15 +124,6 @@ export const initEmpty = () => emptyRecord;
* enforce the `stateShape` invariant. The heap exos defined in this
* package currently ignore `stateShape`, but will enforce this in the future.
*
* @property {ReceivePower<Revoke>} [receiveRevoker]
* If a `receiveRevoker` function is provided, it will be called during
* definition of the exo class or exo class kit with a `Revoke` function.
* A `Revoke` function is a function of one argument. If you call the revoke
* function with a live instance of this exo class, or a live facet instance
* of this exo class kit, then it will "revoke" it and return true. Once
* revoked, this instance is no longer "live": Any attempt to invoke any of
* its methods will fail without further effect.
*
* @property {ReceivePower<Amplify<F>>} [receiveAmplifier]
* If a `receiveAmplifier` function is provided, it will be called during
* definition of the exo class kit with an `Amplify` function. If called
Expand Down Expand Up @@ -190,11 +169,7 @@ export const defineExoClass = (
options = {},
) => {
harden(methods);
const {
finish = undefined,
receiveRevoker = undefined,
receiveAmplifier = undefined,
} = options;
const { finish = undefined, receiveAmplifier = undefined } = options;
receiveAmplifier === undefined ||
Fail`Only facets of an exo class kit can be amplified ${q(tag)}`;

Expand Down Expand Up @@ -227,12 +202,6 @@ export const defineExoClass = (
return self;
};

if (receiveRevoker) {
const revoke = self => contextMap.delete(self);
harden(revoke);
receiveRevoker(revoke);
}

return harden(makeInstance);
};
harden(defineExoClass);
Expand Down Expand Up @@ -260,11 +229,7 @@ export const defineExoClassKit = (
options = {},
) => {
harden(methodsKit);
const {
finish = undefined,
receiveRevoker = undefined,
receiveAmplifier = undefined,
} = options;
const { finish = undefined, receiveAmplifier = undefined } = options;
const contextMapKit = objectMap(methodsKit, () => new WeakMap());
const getContextKit = objectMap(
contextMapKit,
Expand Down Expand Up @@ -302,13 +267,6 @@ export const defineExoClassKit = (
return /** @type {GuardedKit<F>} */ (context.facets);
};

if (receiveRevoker) {
const revoke = aFacet =>
values(contextMapKit).some(contextMap => contextMap.delete(aFacet));
harden(revoke);
receiveRevoker(revoke);
}

if (receiveAmplifier) {
const amplify = aFacet => {
for (const contextMap of values(contextMapKit)) {
Expand All @@ -317,7 +275,7 @@ export const defineExoClassKit = (
return facets;
}
}
throw Fail`Must be an unrevoked facet of ${q(tag)}: ${aFacet}`;
throw Fail`Must be a facet of ${q(tag)}: ${aFacet}`;
};
harden(amplify);
receiveAmplifier(amplify);
Expand Down
19 changes: 1 addition & 18 deletions packages/exo/test/test-amplify-heap-class-kits.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ test('test amplify defineExoClass fails', t => {
});

test('test amplify defineExoClassKit', t => {
let revoke;
let amp;
const makeCounterKit = defineExoClassKit(
'Counter',
Expand All @@ -65,9 +64,6 @@ test('test amplify defineExoClassKit', t => {
},
},
{
receiveRevoker(r) {
revoke = r;
},
receiveAmplifier(a) {
amp = a;
},
Expand All @@ -79,21 +75,8 @@ test('test amplify defineExoClassKit', t => {
t.is(downCounter.decr(), 7);

t.throws(() => amp(harden({})), {
message: 'Must be an unrevoked facet of "Counter": {}',
message: 'Must be a facet of "Counter": {}',
});
t.deepEqual(amp(upCounter), counterKit);
t.deepEqual(amp(downCounter), counterKit);

t.is(revoke(upCounter), true);

t.throws(() => amp(upCounter), {
message: 'Must be an unrevoked facet of "Counter": "[Alleged: Counter up]"',
});
t.deepEqual(amp(downCounter), counterKit);
t.throws(() => upCounter.incr(3), {
message:
'"In \\"incr\\" method of (Counter up)" may only be applied to a valid instance: "[Alleged: Counter up]"',
});
t.deepEqual(amp(downCounter), counterKit);
t.is(downCounter.decr(), 6);
});
121 changes: 0 additions & 121 deletions packages/exo/test/test-revoke-heap-classes.js

This file was deleted.

0 comments on commit d848754

Please sign in to comment.