Open gliechtenstein opened 7 years ago
do i understand this correctly that you are you looking for a way to determine which global variables have been added after loading a script?
if so, could some of the answers in this thread help or do the trick?
Thanks for sharing!
Yup, in fact this is how Cell implements its automatic instantiation mechanism https://github.com/intercellular/cell/blob/develop/cell.js#L501
But the challenge I'm trying to point out here is that currently there's no way to detect whether a variable has already been used or not.
In the example above, we need to detect only the variables that have been dynamically loaded as a result of the script load. The Object.keys(window)
approach will return all the variables, not just the newly added ones. Hope I'm making sense, it's a niche scenario but I think it can be powerful if we can figure this out.
I was trying to implement an app that consists of just an input field initially, which when submitted will dynamically load a remote script and do something on
onload
event, using Cell.More specifically, I was trying to find a way to load a remote cell app from an existing cell app, and inject it into the existing cell app.
But I ran into a problem. When loading a remote script dynamically, it is not possible to know what variables have loaded as a result of that script. The new manual instantiation feature introduced in https://github.com/intercellular/cell/issues/125 doesn't help because we have no knowledge about the newly introduced variables in the root context.
Anyway here's the half-finished code. The only problematic part is the
Fill in the blank here
part insideonload()
. Once that's figured out, everything should just work.Trying to figure out a nice and clean way to tackle this.
it could be done through a modification of the API, or maybe there's a way to do this without modifying the API. Maybe there's a clean way.