-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Common interface to interpret and execute API methods #1016
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
Changes from 1 commit
f2d268d
65f618d
7ef0404
edb6773
f50fcaa
60dd634
4bc8387
93b8253
43dc3d4
65d24f3
d2696e7
7db7f03
57fcf96
7db5f1f
26ad1ff
986b4dc
20ac69f
f993ed7
99d7c8e
f8c0094
6abec15
5df94a7
d35ee35
a554cad
e5a80ee
45717b1
52de9e4
0c40b02
df2d5bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,17 +10,18 @@ | |
'use strict'; | ||
|
||
var Plotly = require('../plotly'); | ||
var Lib = require('../lib'); | ||
var helpers = require('../plot_api/helpers'); | ||
|
||
exports.executeAPICommand = function(gd, method, args) { | ||
var apiMethod = Plotly[method]; | ||
|
||
var allArgs = [gd]; | ||
for (var i = 0; i < args.length; i++) { | ||
for(var i = 0; i < args.length; i++) { | ||
allArgs.push(args[i]); | ||
} | ||
|
||
if (!apiMethod) { | ||
if(!apiMethod) { | ||
return Promise.reject(); | ||
} | ||
|
||
|
@@ -30,30 +31,49 @@ exports.executeAPICommand = function(gd, method, args) { | |
exports.computeAPICommandBindings = function(gd, method, args) { | ||
|
||
switch(method) { | ||
case 'restyle': | ||
var traces | ||
case 'restyle': | ||
var traces; | ||
|
||
// Logic copied from Plotly.restyle: | ||
var astr = args[0]; | ||
var val = args[1]; | ||
var traces = args[2]; | ||
var aobj = {}; | ||
if(typeof astr === 'string') aobj[astr] = val; | ||
else if(Lib.isPlainObject(astr)) { | ||
var astr = args[0]; | ||
var val = args[1]; | ||
var traces = args[2]; | ||
var aobj = {}; | ||
if(typeof astr === 'string') aobj[astr] = val; | ||
else if(Lib.isPlainObject(astr)) { | ||
// the 3-arg form | ||
aobj = astr; | ||
if(traces === undefined) traces = val; | ||
} else { | ||
aobj = astr; | ||
if(traces === undefined) traces = val; | ||
} else { | ||
// This is the failure case, but it's not a concern of this method to fail | ||
// on bad input. This will just return no bindings: | ||
return []; | ||
} | ||
return []; | ||
} | ||
|
||
console.log('aobj:', aobj); | ||
console.log('aobj:', aobj); | ||
|
||
return ['data[0].marker.size']; | ||
break; | ||
default: | ||
throw new Error('Unimplemented'); | ||
return ['data[0].marker.size']; | ||
break; | ||
default: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again here, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess really it should There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now throws error. |
||
// The unknown case. We'll elect to fail-non-fatal since this is a correct | ||
// answer and since this is not a validation method. | ||
return []; | ||
} | ||
}; | ||
|
||
function crawl(attrs, callback, path) { | ||
if(path === undefined) { | ||
path = ''; | ||
} | ||
|
||
Object.keys(attrs).forEach(function(attrName) { | ||
var attr = attrs[attrName]; | ||
|
||
if(exports.UNDERSCORE_ATTRS.indexOf(attrName) !== -1) return; | ||
|
||
callback(attr, attrName, attrs, level); | ||
|
||
if(isValObject(attr)) return; | ||
if(isPlainObject(attr)) crawl(attr, callback, level + 1); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That will never happen, no? Isn't
apiMethod
guaranteed to be defined aftersupplyDefaults
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. I have no strong feelings either way; it's just a general habit analogous to
callback && callback()
in order to ensure I never unexpectedly invokeundefined()
. Thought maybe safety for depending on how it gets used in the future, but I'm fine just removing. I'm not great at proper promise error handling. Few are.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our supply-default machinery is pretty robust. If
apiMethod
somehow becomes undefined at this stage in the future one or many test cases will fail.So, I'd vote for removing these useless checks and instead maybe add a comment about the function declaration saying this function assumes a full round of supply-defaults.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed check 👍