Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined in v3.1.2 #94

Open
kenietz opened this issue Dec 4, 2023 · 4 comments
Open

undefined in v3.1.2 #94

kenietz opened this issue Dec 4, 2023 · 4 comments

Comments

@kenietz
Copy link

kenietz commented Dec 4, 2023

Hi,

i have the following error in v3.1.2: this.plugin is undefined, in function update. I use it to load a second structure(chain). This problem is not existing in v1.2.1 however. I can load 2 structures through the update function.

I checked for similar issues before posting this one and found one. According to that thread it looked like it was solved:

"Mol* core dependency update to v3.8.2 is now available without the above mentioned issue"

Not sure what it means tho :) So i installed nodejs 18.17.0 and build the latest version of the plugin with the hope the error to be gone. But no such luck :)

Any ideas or hints on how to solve the issue will be appreciated!
Thank you for time and help in advance!

Cheers
Dimitar

@midlik
Copy link
Collaborator

midlik commented Jan 23, 2024

Hi,

I'm thinking this issue could be caused by calling the update function before the plugin is fully initialized (i.e. before the asynchronous render function has completed).

I expect your javascript code looks something like this:

const viewerContainer = document.getElementById('myViewer')!;
const viewerInstance = new PDBeMolstarPlugin();
viewerInstance.render(viewerContainer, initOptions);
viewerInstance.visual.update(newOptions, false);

Try to change it to something more like this:

const viewerContainer = document.getElementById('myViewer')!;
const viewerInstance = new PDBeMolstarPlugin();
viewerInstance.render(viewerContainer, initOptions).then(() => viewerInstance.visual.update(newOptions, false));

Also, updating to version 3.1.3 could help.

@midlik
Copy link
Collaborator

midlik commented Jan 23, 2024

Or alternatively

const viewerContainer = document.getElementById('myViewer')!;
const viewerInstance = new PDBeMolstarPlugin();
viewerInstance.render(viewerContainer, initOptions);
viewerInstance.events.loadComplete.subscribe(() => viewerInstance.visual.update(newOptions, false));

@kenietz
Copy link
Author

kenietz commented Feb 8, 2024

Hi,
thank you very much for your reply. I tried both solutions which you provided including using v3.1.3. The following kinda worked:

viewerInstance.render(viewerContainer, initOptions);
viewerInstance.events.loadComplete.subscribe(() => viewerInstance.visual.update(newOptions, false));

Both structures got loaded but then the coloring was weird. The colors of the chains we jumping and changing by themselves :) I guess i would have to change my coloring functions as well in order to make them work with the new version of the plugin. Too much work to do tho haha. So for now i will stick with v1.2.1 of the plugin as everything works well with it.

Thank you again for your time and help!

@midlik
Copy link
Collaborator

midlik commented Aug 29, 2024

Oh, sorry. Loading the second structure actually triggers the loadComplete event again and creates an infinite loop. The jumping chains you saw were probably the same structure being loaded again and again and again and again...

Fortunately, there is an easy fix for this. Just unsubscribe as soon as the event fires for the first time:

const viewerContainer = document.getElementById('myViewer')!;
const viewerInstance = new PDBeMolstarPlugin();
viewerInstance.render(viewerContainer, initOptions);
const subscription = viewerInstance.events.loadComplete.subscribe(() => {
    subscription.unsubscribe();
    viewerInstance.visual.update(newOptions, false);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants