Skip to content

Commit 8161b2d

Browse files
committed
Anchor: expose chainAnchorObjs as public API, refactor chain command to use it
1 parent a8d2365 commit 8161b2d

2 files changed

Lines changed: 36 additions & 8 deletions

File tree

Anchor/2.1.0/anchor.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,10 +1651,7 @@ var Anchor = Anchor || (() => {
16511651
if (ids.length < 2) {
16521652
reply(msg, 'Error', 'Chain requires at least 2 tokens.');
16531653
} else {
1654-
for (var i = 0; i < ids.length; i++) {
1655-
var nextIdx = (i + 1) % ids.length;
1656-
anchorObj(ids[i], ids[nextIdx], comps);
1657-
}
1654+
chainAnchorObjs(ids, comps);
16581655
reply(msg, 'Info', 'Chain-linked ' + ids.length + ' tokens in a ring.');
16591656
}
16601657
}
@@ -1732,6 +1729,22 @@ var Anchor = Anchor || (() => {
17321729
/** Remove the anchor relationship from a child object. */
17331730
const removeAnchor = (childId) => setAnchor(childId, undefined);
17341731

1732+
/**
1733+
* Mutually anchor a list of token IDs in a ring (A→B, B→C, C→A).
1734+
* Move any one and all others follow.
1735+
* `components` is optional; defaults to all components.
1736+
*/
1737+
const chainAnchorObjs = (ids, components) => {
1738+
if (!ids || ids.length < 2) {
1739+
log(SCRIPT_NAME + ': chainAnchorObjs requires at least 2 token IDs.');
1740+
return;
1741+
}
1742+
for (var i = 0; i < ids.length; i++) {
1743+
var nextIdx = (i + 1) % ids.length;
1744+
anchorObj(ids[i], ids[nextIdx], components);
1745+
}
1746+
};
1747+
17351748
/**
17361749
* Programmatically create an invisible auto-anchor token for `obj` and
17371750
* establish the anchor relationship immediately.
@@ -2436,6 +2449,7 @@ var Anchor = Anchor || (() => {
24362449
getUnlocked,
24372450
lock,
24382451
unlock,
2452+
chainAnchorObjs,
24392453
},
24402454
};
24412455
})();

Anchor/anchor.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,10 +1651,7 @@ var Anchor = Anchor || (() => {
16511651
if (ids.length < 2) {
16521652
reply(msg, 'Error', 'Chain requires at least 2 tokens.');
16531653
} else {
1654-
for (var i = 0; i < ids.length; i++) {
1655-
var nextIdx = (i + 1) % ids.length;
1656-
anchorObj(ids[i], ids[nextIdx], comps);
1657-
}
1654+
chainAnchorObjs(ids, comps);
16581655
reply(msg, 'Info', 'Chain-linked ' + ids.length + ' tokens in a ring.');
16591656
}
16601657
}
@@ -1732,6 +1729,22 @@ var Anchor = Anchor || (() => {
17321729
/** Remove the anchor relationship from a child object. */
17331730
const removeAnchor = (childId) => setAnchor(childId, undefined);
17341731

1732+
/**
1733+
* Mutually anchor a list of token IDs in a ring (A→B, B→C, C→A).
1734+
* Move any one and all others follow.
1735+
* `components` is optional; defaults to all components.
1736+
*/
1737+
const chainAnchorObjs = (ids, components) => {
1738+
if (!ids || ids.length < 2) {
1739+
log(SCRIPT_NAME + ': chainAnchorObjs requires at least 2 token IDs.');
1740+
return;
1741+
}
1742+
for (var i = 0; i < ids.length; i++) {
1743+
var nextIdx = (i + 1) % ids.length;
1744+
anchorObj(ids[i], ids[nextIdx], components);
1745+
}
1746+
};
1747+
17351748
/**
17361749
* Programmatically create an invisible auto-anchor token for `obj` and
17371750
* establish the anchor relationship immediately.
@@ -2436,6 +2449,7 @@ var Anchor = Anchor || (() => {
24362449
getUnlocked,
24372450
lock,
24382451
unlock,
2452+
chainAnchorObjs,
24392453
},
24402454
};
24412455
})();

0 commit comments

Comments
 (0)