Skip to content

Fix data binding check #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

n-riesco
Copy link
Owner

@rreusser @etpinard

This fix changes the signature of exports.hasSimpleAPICommandBindings = function(gd, commandList, bindingsByValue, valueByBindings) in a backwards-compatible way (I don't really like the new signature; if compatibility isn't an issue here, I'd pass binding instead of bindingsByValue and valueByBindings).

This change in signature was introduced so that I could search for bindings when the associated value is an array.

* Added lookup table to search commands by value.

Fixes plotly#1169
* Test that API command binding accepts data arrays.
@rreusser
Copy link

This looks great! Unless I'm wrong, it should be able to avoid pathological cases gracefully. The relevant cases seem to be:

  • user passes something like setting visibility, e.g. {method: 'restyle', args: ['visible', [true, false, false]]}. In this case it will check all elements for equality.
  • user passes 10MB of data through an API call… e.g. {method: 'restyle', args: ['x', [[0, 1, 2, ....]]]}. Since resytyle requires the extra nesting inside an array, it shouldn't be the case that this will do a deep comparison through gobs of data. It's important that it's fairly quick to check since it tends to happen a lot.

@n-riesco
Copy link
Owner Author

user passes 10MB of data through an API call… e.g. {method: 'restyle', args: ['x', [[0, 1, 2, ....]]]}.

This PR wouldn't do a deep comparison. Shall I check here whether value is a nested array and return false if so?

@rreusser
Copy link

As long as there's no deep comparison, I think it should be fine, but yeah, probably best to stop this at the hasSimpleBindings level. Thanks for cleaning this up! I failed to appreciate the importance of visibility toggles like this. Is this PR intended for the main plotly.js repo? (It'd definitely be a welcome fix!)

@rreusser
Copy link

rreusser commented Nov 21, 2016

(Hope the code wasn't too difficult to work though! 😄 It was a simple concept that ended up being moderately complicated to actually implement!)


if(obj.hasOwnProperty(binding.prop)) {
if(obj[binding.prop] !== value) {
if(!thisCache.hasOwnProperty(binding.prop)) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove !

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test.


for(commandIndex in binding.valueByBindings) {
var commandValue = binding.valueByBindings[commandIndex];
if(commandValue.length !== value.length) continue;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test

@n-riesco
Copy link
Owner Author

Is this PR intended for the main plotly.js repo? (It'd definitely be a welcome fix!)

Yes, if you're happy with this solution and the signature change in hasSimpleAPICommandBindings.

I guess since plotly#1176 fixes plotly#1169 , there is no rush to merge this PR.

I'll talk to you on Slack tomorrow.

@@ -135,6 +139,39 @@ exports.manageCommandObserver = function(gd, container, commandList, onchange) {
return ret;
};

function getCommandIndex(binding, value) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename binding to observer

@@ -135,6 +139,39 @@ exports.manageCommandObserver = function(gd, container, commandList, onchange) {
return ret;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename ret to observer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants