Extend Stof
Extending Stof with custom libraries.
Last updated
Was this helpful?
Extending Stof with custom libraries.
Last updated
Was this helpful?
Stof is extended with . In a TypeScript context, Stof allows you to call your TypeScript functions directly from Stof using this feature.
In this example, we add a single function called "add" in a Stof library named "CustomLibrary". To call this function from Stof, reference the library name and function name just like any other library: CustomLibrary.add(...)
.
When Stof calls out to TypeScript, it sets the StofDoc as the current context ("this").
In JavaScript, arrow functions do not have a "this" context, so when you define your library functions, do so with the "function" keyword if you intend to work with the document.
The StofDoc is not the same thing as the Stof interface provided by the package. StofDoc is what is held within the Stof interface. Take a look at the for more information and documentation on the StofDoc object.