[ignore] Multiple instances of custom HTML forms

Ignore this question
Read this one instead :

=== ignore this late at night blah blah blah ==
Tying myself up in knots here, wonder if anyone can help?
I might not be explaining this very well, either. But here goes anyway …

I have a custom HTML form which needs to instantiate an instance of an external JS library. My main form may contain 1 or more of these custom forms (or components as they will ultimately be). The parent form will need to be able to call methods on these instantiated objects.

That last bit is the problem. The objects need to be in the global space else they lose scope. But if they are, then it gets messy trying to keep a track of a global array of instantiated objects referenced by name or something. Ideally I want to keep each instance separate but callable.

My first thought was to make a call_js to a function that creates a new object and returns it back to Anvil, but it complains about trying to assign a JS object to a Python variable. I cant serialize it as it complains of cyclic references.

Any ideas or thoughts? Am I going about this the wrong way?

EDIT - I’m using a global array to manage them for now.