As a follow-up to my question Dart JS Library, how to pass callback functions, I want to ensure that any functions passed through to D3 have the right parameters.
So I would like to do something like the following:
@JS('d3')
library d3;
import 'dart:js';
import "package:js/js.dart";
typedef num D3AccessorFunction(List<num> d, num i, List<List<num>> data);
@JS('line')
class Line {
external Line();
external String call (List<List<num>> data);
external Line x(D3AccessorFunction func);
external Line y(num func(List<num> d, num i, List<List<num>> data));
}
Then when I call the method:
Line line = new Line();
line.x(
allowInterop(
(List<num> d, num i, List<List<num>> data) {
return d[0]+10;
}
)
);
I would like it to complain if the parameters aren't matched properly, e.g.,
line.x(
allowInterop(
(List<num> d) {
return d[0]+10;
}
)
);
Unfortunately, the allowInterop swallows this complaint and you can't get rid of it. I've created a work-around (in the d3 definition):
Function d3Function(D3AccessorFunction function) {
return allowInterop(function);
}
Then I call it like this:
line.x(
d3Function(
(List<num> d, num i, List<List<num>> data) {
return d[0]+10;
}
)
);
Which will throw the right errors. But I'd like to know if there's a better way of doing this.