You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the CustomJS plugin loads each class as a singleton by creating an instance and storing it in the window.customJS object. This approach is efficient for shared states but limits the flexibility when multiple instances of the same class are needed in different contexts.
Suggested Enhancement
To increase the flexibility of the CustomJS plugin, I suggest modifying the evalFile method to store the class constructor instead of the instance. This change will allow users to either use a singleton instance (default behavior) or create new instances when required.
Proposed Code Changes
async evalFile(f: string): Promise<void>{try{
const file=awaitthis.app.vault.adapter.read(f);constdef=debuggableEval(`(${file})`,f)asnew()=>unknown;// Store the existing instanceconstcls=newdef();window.customJS[cls.constructor.name]=cls;// Provide a way to create a new instancewindow.customJS[`create${def.name}Instance`]=()=>newdef();}catch(e){console.error(`CustomJS couldn\'t import ${f}`)console.error(e)}}
Description
Currently, the CustomJS plugin loads each class as a singleton by creating an instance and storing it in the window.customJS object. This approach is efficient for shared states but limits the flexibility when multiple instances of the same class are needed in different contexts.
Suggested Enhancement
To increase the flexibility of the CustomJS plugin, I suggest modifying the evalFile method to store the class constructor instead of the instance. This change will allow users to either use a singleton instance (default behavior) or create new instances when required.
Proposed Code Changes
Usage
For the Singleton Instance (default):
For a New Instance (when needed):
The text was updated successfully, but these errors were encountered: