Skip to content

Commit

Permalink
fix: vector attribute issues (#402)
Browse files Browse the repository at this point in the history
* fix: missing scope in vector attributes
* fix: vector attribute get after set issue
  • Loading branch information
npaton authored Aug 25, 2023
1 parent f87c756 commit 05212b8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .changeset/vector-attr-events-missing-scope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@empirica/core": patch
---

Fix missing scope in vector attribute callbacks.

E.g.: In `Empirica.on("stage", "chat", (ctx, { stage, chat }) => {`, where
"chat" is a vector attribute, `stage` was undefined.
5 changes: 5 additions & 0 deletions .changeset/vector-attr-get-after-set-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@empirica/core": patch
---

Fix vector attribute invalid get-after-set value.
6 changes: 5 additions & 1 deletion lib/@empirica/core/src/shared/attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export class Attribute {
}

get nodeID() {
return this.attr?.nodeID || this.attr?.node?.id;
return this.scopeID;
}

// items returns the attribute changes for the current attribute, if it is a
Expand All @@ -284,6 +284,10 @@ export class Attribute {
ao?: Partial<AttributeOptions>,
item?: boolean
): SetAttributeInput {
if (!item && ao?.append && ao!.index === undefined) {
ao!.index = this.attrs?.length || 0;
}

if (!item && ao?.index !== undefined) {
const index = ao!.index!;

Expand Down
2 changes: 1 addition & 1 deletion lib/@empirica/core/src/shared/attributes_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ test("Attribute returns nodeID", (t) => {

const attr = new Attribute(setAttr, "abc", "a");

t.is(attr.nodeID, undefined);
t.is(attr.nodeID, "abc");

attr._update({
id: "1",
Expand Down

0 comments on commit 05212b8

Please sign in to comment.