defining a variable on a companion object does not...
# javascript
b
defining a variable on a companion object does not transpile it as static, but puts it into the constructor
Copy code
class wa {
        constructor() {
            aa = this;
            var t, n, r = {template: ka("applications/settings/configure-regions.hbs")};
            this.PARTS = _a([ne("form", r)]), this.DEFAULT_OPTIONS = {
                tag: "form",
                form: {
                    submitOnChange: !1, handler: (t = this, n = function (n, r, i) {
                        return t.sub(n, r, i)
                    }, n.callableName = "sub", n), closeOnSubmit: !1
                },
                window: {title: "Hey Joe"}
            }
        }
}
is this a bug? Using @JsStatic doesn't generate it either
Copy code
class ConfigureRegions : HandlebarsApplication() {
    companion object {
        @OptIn(ExperimentalJsStatic::class)
        @JsStatic
        var PARTS = recordOf(
            "form" to HandlebarsTemplatePart(
                template = resolveTemplatePath("applications/settings/configure-regions.hbs")
            )
        )
}
1
t
@JsStatic
probably will have effect only with
@JsExport
annotation for class
b
that worked but tests explode
Task :jsProductionExecutableCompileSync
ReferenceError: foundry is not defined at /tmp/_karma_webpack_625642/commons.js7971 java.lang.IllegalStateException: command '/home/bernhard/.gradle/nodejs/node-v22.0.0-linux-x64/bin/node' exited with errors (exit code: 1)
there's also w: file///home/bernhard/dev/pf2e kingmaker tools ng/src/jsMain/kotlin/at/posselt/kingmaker/utils/ConfigureRegions.kt38:9 [NON_EXPORTABLE_TYPE] Exported declaration uses non-exportable return type: 'kotlin.js.Promise<kotlin.Unit>'
t
Promise<Void>
?
b
image.png
t
Copy code
buildPromise {
    ...
    null
}
b
oh
looking at karma, the compiled source looks different than the rest
t
In can depends on build type (develop or production)
b
and ofc that API is only available at runtime when it's inside the browser
probably need to stub it I guess
got it, oh boy, there aren't a lot of docs
I put this into commonTest/resources/foundry-stubs.js
Copy code
const foundry = {
    applications: {
        api: {
            HandlebarsApplicationMixin: (klass) => {
                return class extends klass {
                }
            },
            ApplicationV2: class {
            }
        }
    }
}
then the following into webpack.config.d
Copy code
// load stubs
config.files.unshift("kotlin/foundry-stubs.js")
t
ConfigureRegions::class.js
will give you JS class
Type -
JsClass<ConfigureRegions>
Probably
foundry-stubs.js
isn't required in that case
b
I gave up and put some lipstick on that js api https://dpaste.com/3RK24MHFS
t
Functions you can create in Kotlin/JS
Like here
JsFunction
factory can be used for your goal
b
thank you, right I forgot you could create a JS function from a string