-
Notifications
You must be signed in to change notification settings - Fork 123
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
More advanced custom function tutorial #1108
Conversation
Performance comparison of head (318d094) vs base (aa3f7c0)
|
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.
The page is already good, but with large amounts of text it is easy to add a large amount of comments!
…edoc documentation is generated for it
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.
Partial review
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.
Partial review pt. 2
state, | ||
this.metadata('DOUBLE_RANGE'), | ||
(range) => { | ||
const resultArray = //... |
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.
Is it on purpose that the body of the function is omitted?
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.
Yes, this snippet demonstrates usage of SimpleRangeValue
to return an array
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.
But it does not demonstrate that fully, because the body of the function is missing. I think that a snippet is valuable only if it contains working code.
For one, the fully working example added in handsontable/hyperformula-demos#14 uses internalScalarValueToNumber
, which is not explained here.
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.
In my opinion it would unnecessarily increase the complexity of the guide. A reader can see the fully working example in the demo section if interested in the details.
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.
I think that this is the final review from me. I realize that my comments are "yak shaving", but they come from trying to put the guide in practice. My full journey is documented as commits in https://github.com/handsontable/hyperformula-demos/tree/feature/issue-779-recreation-from-guide-in-typescript
Please decide which of these comments must be applied immediately and which can be postponed after the release.
|
||
In a more advanced example, we'll create a custom function `DOUBLE_RANGE` that takes a range of numbers and returns the range of the same size with all the numbers doubled. | ||
|
||
### Accept a range argument |
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.
I'm lost, because the guide so far presented just one argument type: STRING. Now, it jumps to RANGE, without answering some questions that popped up in my head:
- It is not clear, why only STRING and RANGE types are presented in the guide. Are other types (NUMBER, BOOLEAN, SCALAR, NOERROR, INTEGER, COMPLEX, ANY) more like STRING or more like RANGE or yet totally different?
- When should I use
RANGE
type?
I checked the popularity of all argument types in src
. Here are the results:
- NUMBER - 377
- RANGE - 63
- STRING- 46
- ANY - 33
- NOERROR - 30
- COMPLEX - 25
- INTEGER - 27
- BOOLEAN - 22
- SCALAR - 21
So all of them are useful for some types of functions. It would be good to write a sentence about each of them, and why is RANGE special among them.
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.
You're right. Elaborating more on various argument types would be helpful to a developer of the custom functions. I'll create a follow-up task to do that.
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.
state, | ||
this.metadata('DOUBLE_RANGE'), | ||
(range) => { | ||
const resultArray = //... |
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.
But it does not demonstrate that fully, because the body of the function is missing. I think that a snippet is valuable only if it contains working code.
For one, the fully working example added in handsontable/hyperformula-demos#14 uses internalScalarValueToNumber
, which is not explained here.
this.metadata('DOUBLE_RANGE'), | ||
(range) => { | ||
const resultArray = //... | ||
return SimpleRangeValue.onlyValues(resultArray); |
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.
Some of our built-in functions return SimpleRangeValue.onlyNumbers
and SimpleRangeValue.onlyRanges
. Might I need them? What's the difference between them and SimpleRangeValue.onlyValues
?
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.
It's a valid question. I'll create a follow-up task to elaborate on that.
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.
|
||
### Validate the arguments and return an error | ||
|
||
To handle invalid inputs, the custom function should return an instance of the [`CellError` class](../api/classes/cellerror.md) with the relevant [error type](types-of-errors.md). |
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.
This sentence contradicts with what was said earlier:
To benefit from HyperFormula's automatic validations, wrap your method in the built-in
runFunction()
method, which: (...) Validates arguments passed to your function against your argument validation options.
Can you give more details about what do I need to validate that is not done by runFunction
?
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.
I'll create a follow-up task to elaborate on that.
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.
Codecov Report
@@ Coverage Diff @@
## develop #1108 +/- ##
========================================
Coverage 95.82% 95.82%
========================================
Files 162 162
Lines 14091 14097 +6
Branches 3004 3004
========================================
+ Hits 13503 13509 +6
Misses 588 588
|
Context
Updated demo as a PR in demos repo. Works in CodeSandbox (sandbox support for the unit tests works).
ArgumentTypes
interface toFunctionArgumentType
and export it for typescript usersHow did you test your changes?
Types of changes
Related issues:
Fixes #779
Checklist: