Skip to content

Commit

Permalink
refactor(exo): "live" qualifier no longer needed
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Jan 18, 2024
1 parent 7556f21 commit 1ddc51a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
26 changes: 13 additions & 13 deletions packages/exo/src/exo-makers.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const initEmpty = () => emptyRecord;
*/

/**
* The power to amplify a live facet instance of the associated exo class kit
* The power to amplify a facet instance of the associated exo class kit
* into the record of all facets of this facet instance's cohort.
*
* @template {any} [F=any]
Expand All @@ -98,13 +98,13 @@ export const initEmpty = () => emptyRecord;
*/

/**
* The power to test if a value is a live instance of the
* associated exo class, or a live facet instance of the
* The power to test if a value is an instance of the
* associated exo class, or a facet instance of the
* associated exo class kit. In the later case, if a `facetName` is provided,
* then it tests only whether the argument is a facet instance of that
* facet of the associated exo class kit.
*
* @callback IsLiveInstance
* @callback IsInstance
* @param {any} exo
* @param {string} [facetName]
* @returns {boolean}
Expand Down Expand Up @@ -142,14 +142,14 @@ export const initEmpty = () => emptyRecord;
* definition of the exo class kit with an `Amplify` function. If called
* during the definition of a normal exo or exo class, it will throw, since
* only exo kits can be amplified.
* An `Amplify` function is a function that takes a live facet instance of
* An `Amplify` function is a function that takes a facet instance of
* this class kit as an argument, in which case it will return the facets
* record, giving access to all the facet instances of the same cohort.
*
* @property {ReceivePower<IsLiveInstance>} [receiveInstanceTester]
* @property {ReceivePower<IsInstance>} [receiveInstanceTester]
* If a `receiveInstanceTester` function is provided, it will be called
* during the definition of the exo class or exo class kit with an
* `IsLiveInstance` function. The first argument of `IsLiveInstance`
* `IsInstance` function. The first argument of `IsInstance`
* is the value to be tested. When it may be a facet instance of an
* exo class kit, the optional second argument, if provided, is
* a `facetName`. In that case, the function tests only if the first
Expand Down Expand Up @@ -229,15 +229,15 @@ export const defineExoClass = (
};

if (receiveInstanceTester) {
const isLiveInstance = (exo, facetName = undefined) => {
const isInstance = (exo, facetName = undefined) => {
facetName === undefined ||
Fail`facetName can only be used with an exo class kit: ${q(
tag,
)} has no facet ${q(facetName)}`;
return contextMap.has(exo);
};
harden(isLiveInstance);
receiveInstanceTester(isLiveInstance);
harden(isInstance);
receiveInstanceTester(isInstance);
}

return harden(makeInstance);
Expand Down Expand Up @@ -324,7 +324,7 @@ export const defineExoClassKit = (
}

if (receiveInstanceTester) {
const isLiveInstance = (exoFacet, facetName = undefined) => {
const isInstance = (exoFacet, facetName = undefined) => {
if (facetName === undefined) {
return values(contextMapKit).some(contextMap =>
contextMap.has(exoFacet),
Expand All @@ -336,8 +336,8 @@ export const defineExoClassKit = (
Fail`exo class kit ${q(tag)} has no facet named ${q(facetName)}`;
return contextMap.has(exoFacet);
};
harden(isLiveInstance);
receiveInstanceTester(isLiveInstance);
harden(isInstance);
receiveInstanceTester(isInstance);
}

return harden(makeInstanceKit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const DownCounterI = M.interface('DownCounter', {
decr: M.call().optional(M.gte(0)).returns(M.number()),
});

test('test isLiveInstance defineExoClass', t => {
let isLiveInstance;
test('test isInstance defineExoClass', t => {
let isInstance;
const makeUpCounter = defineExoClass(
'UpCounter',
UpCounterI,
Expand All @@ -31,27 +31,27 @@ test('test isLiveInstance defineExoClass', t => {
},
{
receiveInstanceTester(i) {
isLiveInstance = i;
isInstance = i;
},
},
);
t.is(isLiveInstance(harden({})), false);
t.throws(() => isLiveInstance(harden({}), 'up'), {
t.is(isInstance(harden({})), false);
t.throws(() => isInstance(harden({}), 'up'), {
message:
'facetName can only be used with an exo class kit: "UpCounter" has no facet "up"',
});

const upCounter = makeUpCounter(3);

t.is(isLiveInstance(upCounter), true);
t.throws(() => isLiveInstance(upCounter, 'up'), {
t.is(isInstance(upCounter), true);
t.throws(() => isInstance(upCounter, 'up'), {
message:
'facetName can only be used with an exo class kit: "UpCounter" has no facet "up"',
});
});

test('test isLiveInstance defineExoClassKit', t => {
let isLiveInstance;
test('test isInstance defineExoClassKit', t => {
let isInstance;
const makeCounterKit = defineExoClassKit(
'Counter',
{ up: UpCounterI, down: DownCounterI },
Expand All @@ -75,23 +75,23 @@ test('test isLiveInstance defineExoClassKit', t => {
},
{
receiveInstanceTester(i) {
isLiveInstance = i;
isInstance = i;
},
},
);

t.is(isLiveInstance(harden({})), false);
t.is(isLiveInstance(harden({}), 'up'), false);
t.throws(() => isLiveInstance(harden({}), 'foo'), {
t.is(isInstance(harden({})), false);
t.is(isInstance(harden({}), 'up'), false);
t.throws(() => isInstance(harden({}), 'foo'), {
message: 'exo class kit "Counter" has no facet named "foo"',
});

const { up: upCounter } = makeCounterKit(3);

t.is(isLiveInstance(upCounter), true);
t.is(isLiveInstance(upCounter, 'up'), true);
t.is(isLiveInstance(upCounter, 'down'), false);
t.throws(() => isLiveInstance(upCounter, 'foo'), {
t.is(isInstance(upCounter), true);
t.is(isInstance(upCounter, 'up'), true);
t.is(isInstance(upCounter, 'down'), false);
t.throws(() => isInstance(upCounter, 'foo'), {
message: 'exo class kit "Counter" has no facet named "foo"',
});
});

0 comments on commit 1ddc51a

Please sign in to comment.