Skip to content

Conversation

@p3rcypj
Copy link

@p3rcypj p3rcypj commented Feb 28, 2025

📌 References

📝 Implementation

  • Fix default chain not being shown on chains dropdown
  • When changing from 8via to 6zow for example, it was not removing correctly the previous emdb. Therefore, a function to deal with all unused items after updates was implemented.
  • On init the default chain was being applied correctly, but when the PDB ID, the function execution was completely out place, along with the different chain of dependencies changing at the same time. Causing all of this an orthogonal problem. A comment was attached to the code to be aware of this in future
/* Rendering cycle issue to be aware of:
*
* On recent changes, pdbInfo was added to the props of MolecularStructure, and usePdbPlugin was updated to use it.
* And as pdbInfo is also changed by selection, it triggers two times the function updatePluginOnNewSelection inside usePdbPlugin,
* as that callback is used in a useEffect with its dependencies.
* Therefore, when selection changes, it changes at the same time both pdbInfo and usePdbPlugin. And after pdbInfo has changed, as it has changed,
* it changes usePdbPlugin again, causing the plugin to be updated twice.
*
* The conceptual solution approach would be to put selection inside pdbInfo, and use selection as pdbInfo.selection.
* That way, when selection changes, it will change pdbInfo, and then usePdbPlugin will be updated only once.
*/

@adrianq adrianq merged commit 7a72626 into development Mar 17, 2025
1 check passed
@p3rcypj p3rcypj requested a review from tokland March 19, 2025 09:34
Copy link

@tokland tokland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The plugin controlling code is not pretty (React code that controls an external imperative library never is), but if it works, it's still a idiomatic workflow. I added some minor comments that need no re-open, just for the record.

const ligandId = newSelection.ligandId;
const chains = React.useMemo(() => options.pdbInfo?.chains ?? [], [options.pdbInfo?.chains]);

const chains = React.useMemo(() => pdbInfo?.chains ?? [], [pdbInfo?.chains]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not important, but here you are using useMemo as a way to keep the value immutable when it takes the fallback empty array, right? In that case, the typical approach is: const chains = pdbInfo?.changes || emptyArray. Where const emptyArray = [] is defined at the root level, so it's immutable.

}

function pdbeMolstarSequenceEventCompletedWrapper(callback: () => void) {
return (sequence: any) => {
Copy link

@tokland tokland Mar 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor] as discussed in the other PR, when we don't really care about the type, it's safer to put "unknown"

@p3rcypj
Copy link
Author

p3rcypj commented Mar 19, 2025

Thank you @tokland for the review and your comments!

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

Successfully merging this pull request may close these issues.

3 participants