Modules

As the complexity of your system grows you may wish to extract common functionality to a single place for maintainability. Script modules are how organizing shared code in Konfoo works.

All script modules are accessible from both compute fields and aggregators.

To define a new script module add a scripts entry to your main domain definition file options block:

options:
    scripts:
        my_module: relative/path/to/my_module.rhai

This will load my_module.rhai from your path as a my_module:: global script module.

If my_module.rhai looked like this:

fn my_function() {
    return 42;
}

then in a compute field you could access that function like this:

computed_field:
    type: compute
    onchange:
        - param
    code: |
        fn main() {
            not_null(self.param);
            return my_module::my_function() * self.param;
        }