From 8534a8e8e05da62d2e2fa4a2adfa4581f294d40d Mon Sep 17 00:00:00 2001 From: Jack Blazes Date: Tue, 12 Aug 2025 14:03:36 -0700 Subject: [PATCH 1/6] calls transform function on constant attribute updates Fixes bugs that show up when inputting an accessor as a string instead of a function --- modules/core/src/lib/attribute/attribute-manager.ts | 4 ++-- modules/core/src/lib/attribute/attribute.ts | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/core/src/lib/attribute/attribute-manager.ts b/modules/core/src/lib/attribute/attribute-manager.ts index 8d518893cdb..4a117d308e4 100644 --- a/modules/core/src/lib/attribute/attribute-manager.ts +++ b/modules/core/src/lib/attribute/attribute-manager.ts @@ -208,7 +208,7 @@ export default class AttributeManager { } else if ( typeof accessorName === 'string' && !buffers[accessorName] && - attribute.setConstantValue(props[accessorName]) + attribute.setConstantValue(props[accessorName], context) ) { // Step 3: try set constant value from props // Note: if buffers[accessorName] is supplied, ignore props[accessorName] @@ -380,7 +380,7 @@ export default class AttributeManager { // The attribute is flagged as constant outside of an update cycle // Skip allocation and updater call // @ts-ignore value can be set to an array by user but always cast to typed array during attribute update - attribute.setConstantValue(attribute.value); + attribute.setConstantValue(attribute.value, context); return; } diff --git a/modules/core/src/lib/attribute/attribute.ts b/modules/core/src/lib/attribute/attribute.ts index d2c532bdee9..b29274f5200 100644 --- a/modules/core/src/lib/attribute/attribute.ts +++ b/modules/core/src/lib/attribute/attribute.ts @@ -254,7 +254,7 @@ export default class Attribute extends DataColumn Date: Tue, 12 Aug 2025 14:25:49 -0700 Subject: [PATCH 2/6] styling fix --- modules/core/src/lib/attribute/attribute.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/modules/core/src/lib/attribute/attribute.ts b/modules/core/src/lib/attribute/attribute.ts index b29274f5200..db62d6d867a 100644 --- a/modules/core/src/lib/attribute/attribute.ts +++ b/modules/core/src/lib/attribute/attribute.ts @@ -270,14 +270,8 @@ export default class Attribute extends DataColumn Date: Wed, 20 Aug 2025 11:36:47 -0700 Subject: [PATCH 3/6] testing and styling --- .../src/lib/attribute/attribute-manager.ts | 4 +-- modules/core/src/lib/attribute/attribute.ts | 8 +++-- .../core/lib/attribute/attribute.spec.ts | 29 ++++++++++++++----- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/modules/core/src/lib/attribute/attribute-manager.ts b/modules/core/src/lib/attribute/attribute-manager.ts index 4a117d308e4..59d791c2893 100644 --- a/modules/core/src/lib/attribute/attribute-manager.ts +++ b/modules/core/src/lib/attribute/attribute-manager.ts @@ -208,7 +208,7 @@ export default class AttributeManager { } else if ( typeof accessorName === 'string' && !buffers[accessorName] && - attribute.setConstantValue(props[accessorName], context) + attribute.setConstantValue(context, props[accessorName]) ) { // Step 3: try set constant value from props // Note: if buffers[accessorName] is supplied, ignore props[accessorName] @@ -380,7 +380,7 @@ export default class AttributeManager { // The attribute is flagged as constant outside of an update cycle // Skip allocation and updater call // @ts-ignore value can be set to an array by user but always cast to typed array during attribute update - attribute.setConstantValue(attribute.value, context); + attribute.setConstantValue(context, attribute.value); return; } diff --git a/modules/core/src/lib/attribute/attribute.ts b/modules/core/src/lib/attribute/attribute.ts index db62d6d867a..f49b571d804 100644 --- a/modules/core/src/lib/attribute/attribute.ts +++ b/modules/core/src/lib/attribute/attribute.ts @@ -254,7 +254,7 @@ export default class Attribute extends DataColumn { t.ok(attribute.allocate(4), 'allocate successful'); t.is(attribute.value, allocatedValue, 'reused the same typed array'); - attribute.setConstantValue([1, 1]); + attribute.setConstantValue(this, [1, 1]); t.deepEquals(attribute.value, [1, 1], 'value overwritten by external constant'); - attribute.setConstantValue(undefined); + attribute.setConstantValue(this, undefined); t.ok(attribute.allocate(4), 'allocate successful'); t.is(attribute.value, allocatedValue, 'reused the same typed array'); @@ -136,14 +136,14 @@ test('Attribute#setConstantValue', t => { t.ok(attribute.getValue().positions instanceof Buffer, 'attribute is using packed buffer'); attribute.needsRedraw({clearChangedFlags: true}); - attribute.setConstantValue([0, 0, 0]); + attribute.setConstantValue(this, [0, 0, 0]); t.deepEqual(attribute.getValue().positions, [0, 0, 0], 'attribute set to constant value'); t.ok(attribute.needsRedraw({clearChangedFlags: true}), 'attribute marked needs redraw'); - attribute.setConstantValue([0, 0, 0]); + attribute.setConstantValue(this, [0, 0, 0]); t.notOk(attribute.needsRedraw({clearChangedFlags: true}), 'attribute should not need redraw'); - attribute.setConstantValue([0, 0, 1]); + attribute.setConstantValue(this, [0, 0, 1]); t.deepEqual(attribute.getValue().positions, [0, 0, 1], 'attribute set to constant value'); t.ok(attribute.needsRedraw({clearChangedFlags: true}), 'attribute marked needs redraw'); @@ -156,7 +156,7 @@ test('Attribute#setConstantValue', t => { accessor: 'getColor' }); - attribute.setConstantValue([255, 255, 0]); + attribute.setConstantValue(this, [255, 255, 0]); t.deepEqual(attribute.getValue().colors, [1, 1, 0], 'constant value is normalized'); t.end(); @@ -277,7 +277,8 @@ test('Attribute#updateBuffer', t => { {id: 'E', value: 0, color: undefined} ], getColor: d => d.color, - getValue: d => d.value + getValue: d => d.value, + getValueConstant: [20] }; const TEST_PARAMS = [ @@ -341,6 +342,18 @@ test('Attribute#updateBuffer', t => { standard: [20, 40, 14, 0], 'variable size': [20, 20, 40, 14, 14, 14, 14, 0, 0, 0] }, + { + title: 'constant accessor with transform', + attribute: new Attribute(device, { + id: 'values', + type: 'float32', + size: 1, + accessor: 'getValueConstant', + transform: x => x * 2 + }), + standard: [40, 40, 40, 40], + 'variable size': [40, 40, 40, 40, 40, 40, 40, 40, 40, 40] + }, { title: 'custom accessor', attribute: new Attribute(device, { @@ -1114,7 +1127,7 @@ test('Attribute#updateBuffer', t => { t.is(bounds, attribute.getBounds(), 'bounds is cached'); attribute.setNeedsUpdate(); - attribute.setConstantValue([-1, 0, 1]); + attribute.setConstantValue(this, [-1, 0, 1]); bounds = attribute.getBounds(); t.deepEqual( From 7e21a6b39b33fd29f92dbbd9f284e10332d916a9 Mon Sep 17 00:00:00 2001 From: Jack Blazes Date: Fri, 29 Aug 2025 13:20:18 -0700 Subject: [PATCH 4/6] fix context issue --- modules/core/src/lib/attribute/attribute.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/lib/attribute/attribute.ts b/modules/core/src/lib/attribute/attribute.ts index f49b571d804..9e37cf0a6ba 100644 --- a/modules/core/src/lib/attribute/attribute.ts +++ b/modules/core/src/lib/attribute/attribute.ts @@ -270,7 +270,7 @@ export default class Attribute extends DataColumn Date: Tue, 2 Sep 2025 01:41:43 -0700 Subject: [PATCH 5/6] linting fix --- modules/core/src/lib/attribute/attribute.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/core/src/lib/attribute/attribute.ts b/modules/core/src/lib/attribute/attribute.ts index 9e37cf0a6ba..8e73919cb38 100644 --- a/modules/core/src/lib/attribute/attribute.ts +++ b/modules/core/src/lib/attribute/attribute.ts @@ -270,9 +270,8 @@ export default class Attribute extends DataColumn Date: Fri, 3 Oct 2025 17:20:13 -0700 Subject: [PATCH 6/6] attribute manager fix --- modules/core/src/lib/attribute/attribute-manager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/lib/attribute/attribute-manager.ts b/modules/core/src/lib/attribute/attribute-manager.ts index 59d791c2893..bd471597478 100644 --- a/modules/core/src/lib/attribute/attribute-manager.ts +++ b/modules/core/src/lib/attribute/attribute-manager.ts @@ -380,7 +380,7 @@ export default class AttributeManager { // The attribute is flagged as constant outside of an update cycle // Skip allocation and updater call // @ts-ignore value can be set to an array by user but always cast to typed array during attribute update - attribute.setConstantValue(context, attribute.value); + attribute.setConstantValue(opts.context, attribute.value); return; }