Skip to content

Commit e104c7d

Browse files
committed
fix: add equality checks to domain-raw and interplote
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent b830dae commit e104c7d

File tree

2 files changed

+34
-14
lines changed
  • lib/node_modules/@stdlib/plot/vega/scale/base/ctor/lib

2 files changed

+34
-14
lines changed

lib/node_modules/@stdlib/plot/vega/scale/base/ctor/lib/domain-raw/set.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
// MODULES //
2424

2525
var logger = require( 'debug' );
26+
var hasSameValues = require( '@stdlib/array/base/assert/has-same-values' );
2627
var isCollection = require( '@stdlib/assert/is-collection' );
2728
var isUndefined = require( '@stdlib/assert/is-undefined' );
2829
var copy = require( '@stdlib/utils/copy' );
@@ -51,16 +52,34 @@ var debug = logger( 'vega:scale:set:'+prop.name );
5152
* @returns {void}
5253
*/
5354
function set( value ) {
54-
if ( !isCollection( value ) && !isUndefined( value ) ) {
55+
var curr;
56+
var flg;
57+
58+
flg = isCollection( value );
59+
if ( !flg && !isUndefined( value ) ) {
5560
throw new TypeError( format( 'invalid assignment. `%s` must be an array-like object. Value: `%s`.', prop.name, value ) );
5661
}
62+
curr = this[ prop.private ];
5763

58-
// FIXME: should we perform a deep equal check here in order to avoid a potential false positive change event?
59-
60-
value = copy( value );
61-
debug( 'Current value: %s. New value: %s.', JSON.stringify( this[ prop.private ] ), JSON.stringify( value ) );
62-
this[ prop.private ] = value;
63-
this.emit( 'change', changeEvent( prop.name ) );
64+
// Case: collection ?= current
65+
if ( flg ) {
66+
// Check for element-wise equality...
67+
if ( isCollection( curr ) && hasSameValues( value, curr ) ) {
68+
return;
69+
}
70+
value = copy( value ); // TODO: is deep copying necessary here? If the domain can include, e.g., objects, it is. If only primitives, it is less necessary.
71+
debug( 'Current value: %s. New value: %s.', JSON.stringify( this[ prop.private ] ), JSON.stringify( value ) );
72+
this[ prop.private ] = value;
73+
this.emit( 'change', changeEvent( prop.name ) );
74+
return;
75+
}
76+
// Case: void ?= current
77+
if ( curr !== value ) {
78+
value = copy( value );
79+
debug( 'Current value: %s. New value: %s.', JSON.stringify( this[ prop.private ] ), JSON.stringify( value ) );
80+
this[ prop.private ] = value;
81+
this.emit( 'change', changeEvent( prop.name ) );
82+
}
6483
}
6584

6685

lib/node_modules/@stdlib/plot/vega/scale/base/ctor/lib/interpolate/set.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
// MODULES //
2424

2525
var logger = require( 'debug' );
26+
var isDeepEqual = require( '@stdlib/assert/deep-equal' );
2627
var isInterpolationMethod = require( '@stdlib/plot/vega/base/assert/is-scale-range-interpolation-method' );
2728
var isObject = require( '@stdlib/assert/is-object' );
2829
var isUndefined = require( '@stdlib/assert/is-undefined' );
@@ -56,13 +57,13 @@ function set( value ) {
5657
if ( !flg && !isObject( value ) && !isUndefined( value ) ) {
5758
throw new TypeError( format( 'invalid assignment. `%s` must be either an object or a valid interpolation method. Value: `%s`.', prop.name, value ) );
5859
}
59-
value = copy( value );
60-
61-
// FIXME: should we perform a deep equal comparison to avoid triggering a false positive change event?
62-
63-
debug( 'Current value: %s. New value: %s.', this[ prop.private ], value );
64-
this[ prop.private ] = value;
65-
this.emit( 'change', changeEvent( prop.name ) );
60+
// TODO: explore whether we can be more intelligent when performing deep equality checks for an interpolation object rather than relying on a general deep equality check.
61+
if ( !isDeepEqual( value, this[ prop.private ] ) ) {
62+
value = copy( value );
63+
debug( 'Current value: %s. New value: %s.', this[ prop.private ], value );
64+
this[ prop.private ] = value;
65+
this.emit( 'change', changeEvent( prop.name ) );
66+
}
6667
}
6768

6869

0 commit comments

Comments
 (0)