Create your dynamic value class
Create your dynamic value class
An Extension is represented as a JavaScript class.
Methods
Dynamic Values must have three methods:
evaluate(context)
Required: evaluates the result of the Dynamic Value evaluation
title(context)
Required: returns the title to show in the Dynamic Value token
text(context)
Required: returns the text to show in the Dynamic Value token
Static properties
Also, the class object have these properties:
identifier
Required: the extension identifier
title
Required: the extension display name
inputs
Optional: the inputs the dynamic value will have (if any)
help
Optional: a URI pointing to the dynamic value documentation (if any)
Example
// Extensions are implemented as JavaScript classes
var MyDynamicValue = function() {
// implement the evaluate() method to generate the dynamic value
this.evaluate = function() {
var dynamicValue = ""; // generate some dynamic value
return dynamicValue;
}
}
// set the Extension Identifier (must be same as the directory name)
MyDynamicValue.identifier = "com.mycompany.MyDynamicValue";
// give a display name to your Dynamic Value
MyDynamicValue.title = "My Dynamic Value";
// link to the Dynamic Value documentation
MyDynamicValue.help = "https://paw.cloud/doc/";
// call to register function is required
registerDynamicValueClass(MyDynamicValue)
Implement evaluate()
Implement evaluate()
Implement the evaluate(context) method and return the value you want to generate:
Here’s how you’d do to implement a dynamic value that returns the factorial of a number:
this.evaluate = function(context) {
var f = function(x) {
if (x == 0) {
return 1;
}
else {
return x * f(x - 1);
}
}
// get the user input(s)
var myNumber = this.number;
// return the result value
return f(myNumber);
}
Implement title() and text()
Implement title() and text()
These methods return the text to be displayed in the dynamic value token.
this.title = function(context) {
return "Factorial";
}
this.text = function(context) {
return this.number.toString() + "!";
}