Hey guys, I'm making a panel that uses the CodeMirror library to act like a pocket IDE / native text editor for scripting, that can 'load' (by writing to a .jsx file which is immediately $.evalFile'd) snippets of jsx and transfer any error messages between:
This works really well and I like the idea of these independent "notesnippets" to work with in a sandbox, but I'm not sure how I would edit or delete them after using $.evalFile on these snippets. Since I write to a file then $.evalFile(), I don't know how to do the opposite -- say I want to edit the snippet's contents then reload them so their values are updated, I notice that the original values still remain even if I:
1) Rewrite the contents of the file then $.evalFile() it again
2) Delete the file, then write and eval or doScript() it.
3) Try uneval() (which I'm sure isn't for this purpose, but I can't find any explanations of it's use and hardly any examples online, of which I don't understand the context of)
So I imagine that using $.evalFile() is returning a new instance while the original instance is still being evaluated without regard to the referenced file's current contents? Can I delete a $.evalFile()'s results from memory in order to clear it without refreshing the extension, which would allow me to subsequently write new values in with a new $.evalFile() using variables or functions with the same name? Overwrite, modify or delete them?
Still stumped by this, and I'm pretty new to coding so I may be overlooking something really obvious but I'd appreciate any input.
I realize that I could store all the information; like how many snippets and what their contents are; in persistent cookies or through I/O via adobe.cep.fs.readFile then simply reload the panel each time I remove or make a modification to any given snippet to effectively rebuild the UI and eval stack to solve this problem, but that seems like a hacky solution and I'd like that to be a last resort.
Is there any way (through JS, JSX or any other means) to remove or uneval a script after having used $.evalFile to initialize it?
It really depends on how messy the loaded file looks like but you could set loaded vars to null and call garbage collector with $.gc();
Hi Loic, that sounds really promising. I looked in the ESTK OMV's description and read the MDN doc about garbage collection, but I only see discussions mentioning it's use without solid examples for Adobe scripting.
The loaded files (if we're not talking the main extension and only snippets) are meant to be very small, just a few lines or so, should only contain variables or functions without allowing anything else, and ideally shouldn't be messy at all. I only want to clear/delete the snippet if pressing the garbage can on the right side of the panel in the demo in the original post so it's no longer available during this session.
Can you point out what's wrong here?
// example full snippet:
var example = app.documents.name;
example = null;
It returns null, but I'm guessing it should return undefined if it actually cleared. I already have a function that splices variable and function names from the snippet (for the preview of the snippet's title) and could set those to null through another function then eval them over again. I feel like if I had to automate setting the loaded variables to null before running garbage collection regardless, then I might as well just leave it at setting them to null unless there'd be any concern with memory or bad practice doing it that way?
I'm sorry for the necro here - but calling $.gc() in the same function as the variable you want to null would do nothing since it's still in scope - and, according to how the script is reading it, very much in play - even though its value is now null. That's why it returns null and not undefined. Maybe execute the block in an inner func and null it there - then call $.gc() afterward.