Skip to content

Docs: expanding the Custom Functions topic - #758

Merged
kirszenbaum merged 32 commits into
developfrom
feature/issue-557
Jul 15, 2021
Merged

Docs: expanding the Custom Functions topic#758
kirszenbaum merged 32 commits into
developfrom
feature/issue-557

Conversation

@kirszenbaum

Copy link
Copy Markdown
Contributor

#557

In Custom Functions:

  • Added an "Optional parameters" section, based on this
  • Added an "Argument validation options" section, based on this
  • Added a "runFunction()" section
  • Added a "Throwing errors" section, based on this

@kirszenbaum kirszenbaum added the Docs Improvements or additions to documentation label Jul 7, 2021
@kirszenbaum
kirszenbaum requested a review from izulin July 7, 2021 12:41
@kirszenbaum kirszenbaum linked an issue Jul 7, 2021 that may be closed by this pull request
5 tasks
@codecov

codecov Bot commented Jul 7, 2021

Copy link
Copy Markdown

Codecov Report

Merging #758 (3cf186b) into develop (321406c) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #758   +/-   ##
========================================
  Coverage    92.35%   92.35%           
========================================
  Files          166      166           
  Lines        40311    40330   +19     
  Branches      5569     5569           
========================================
+ Hits         37229    37248   +19     
  Misses        3039     3039           
  Partials        43       43           
Impacted Files Coverage Δ
src/interpreter/plugin/FunctionPlugin.ts 81.63% <100.00%> (+0.72%) ⬆️

Comment thread docs/guide/custom-functions.md Outdated
Comment thread docs/guide/custom-functions.md Outdated
Comment thread docs/guide/custom-functions.md Outdated
Comment thread docs/guide/custom-functions.md Outdated
wojciechczerniak and others added 5 commits July 7, 2021 17:35
Co-authored-by: Wojciech Czerniak <wojciech.czerniak@gmail.com>
Co-authored-by: Wojciech Czerniak <wojciech.czerniak@gmail.com>
Comment thread docs/guide/custom-functions.md
Comment thread docs/guide/custom-functions.md Outdated
Comment thread docs/guide/custom-functions.md Outdated
Comment thread docs/guide/custom-functions.md Outdated
Comment thread docs/guide/custom-functions.md Outdated
Comment thread docs/guide/custom-functions.md Outdated
Comment thread docs/guide/custom-functions.md Outdated
Comment thread docs/guide/custom-functions.md Outdated
Comment on lines +282 to +292
public hyper({ args }) {
if (!args.length) {
// create a `CellError` instance with an `ErrorType` of `DIV_BY_ZERO`
// with your custom error message (optional)
return new CellError(ErrorType.DIV_BY_ZERO, 'Sorry, cannot divide by zero!');
}

else {
return 'Hyperformula'.length;
}
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wrong formatting and I think we're missing plugin class here

Suggested change
public hyper({ args }) {
if (!args.length) {
// create a `CellError` instance with an `ErrorType` of `DIV_BY_ZERO`
// with your custom error message (optional)
return new CellError(ErrorType.DIV_BY_ZERO, 'Sorry, cannot divide by zero!');
}
else {
return 'Hyperformula'.length;
}
};
export class CountHF extends FunctionPlugin {
public hyper({ args }) {
if (!args.length) {
// create a `CellError` instance with an `ErrorType` of `DIV_BY_ZERO`
// with your custom error message (optional)
return new CellError(ErrorType.DIV_BY_ZERO, 'Sorry, cannot divide by zero!');
}
else {
return 'Hyperformula'.length;
}
};
}

All imports are already in place

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Or make it more obvious that we're focusing on the body of our method because complete functions will be added below. Then we should remove the imports, fix indentation, add a comment that this is part of the CountHF class etc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@wojciechczerniak - sure. I think I'd rather display the whole example (except optional parameters) in each step, WDYT? I also checked the indendation in all the code samples: 5b0f149

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤔 With translations and aliases it's a little bit harder to find what has changed between steps. Also the "complete" examples is a copy of last step without any changes and this sections makes little sense. But I don't have a better idea right now


## A complete example of the class definition

To sum up, here is a complete example of a custom `CountHF` class:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The complete examples is now shorter than each step 😄 We should update the example below

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ale at the bottom of the page we have CodeSandbox with working demo. We should make sure it's up do date with this tutorial

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread docs/guide/custom-functions.md Outdated
Comment thread docs/guide/custom-functions.md Outdated
Comment thread docs/guide/custom-functions.md Outdated
Comment thread docs/guide/custom-functions.md Outdated
Comment thread docs/guide/custom-functions.md Outdated
Comment thread docs/guide/custom-functions.md Outdated
@wojciechczerniak

Copy link
Copy Markdown
Contributor

With translations added as static key on the plugin class the "using plugin" section have to change:

import Hyperformula, { plPL } from 'hyperformula';
import { CountHF } from './file_with_your_custom_function';
- import { myTranslations } from '/myTranslationFile';

// register the language
HyperFormula.registerLanguage('plPL', plPL);

// register your custom plugin and the translation
- HyperFormula.registerFunctionPlugin(CountHF, myTranslations);
+ HyperFormula.registerFunctionPlugin(CountHF, CountHF.translations);

// build HF instance where you can use the function directly
const hfInstance = HyperFormula.buildFromArray([['=HAJPER()']]);

// read the value of cell A1
const A1Value = hfInstance.getCellValue({ sheet: 0, col: 0, row: 0 });

// open the browser's console to see the results
console.log(A1Value);

@kirszenbaum

Copy link
Copy Markdown
Contributor Author

@wojciechczerniak - translation updated: a1f532b, d786b8a

@wojciechczerniak wojciechczerniak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🏆

@kirszenbaum
kirszenbaum merged commit bc92b19 into develop Jul 15, 2021
@kirszenbaum
kirszenbaum deleted the feature/issue-557 branch July 15, 2021 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Docs Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve Custom Functions page

3 participants