Code Monkey home page Code Monkey logo

Comments (4)

ppillot avatar ppillot commented on June 2, 2024

Thanks for your contribution. I think it's fine to export things we need from the library given that NGL is quite monolithic and not amenable to tree shaking.

Regarding the parser, I've used in past projects the ParserRegistry object that is exported from NGL to get some parsers in my code and even redefine some methods via their prototype.

const pdbParser = ParserRegistry.get('pdb')
pdbParser.prototype._beforeParse = // ... overriding code goes there

What is the use case for exporting the NetworkStreamer? Is it to override some of its methods?

from ngl.

FLIGHTLAMA avatar FLIGHTLAMA commented on June 2, 2024

Thanks for the answer, I didn't know about the possibility to use the ParserRegistry, but it should solve the problem,

Yes indeed, it is to overwrite a method (see example). The main reason for this is that the state and api queries are conveniently managed via React/Redux.
This makes it very easy to integrate the viewer into the normal flow and let the react/redux handel all the data/api calls updates caching etc...

// Use Structure data from the state
   const compound3DStructure = useAppSelector(getStructure3D);

  const createNetworkStreamer = (result: string) => {
    const networkInputStream = new NetworkStreamer("custom", {
      compressed: false,
      binary: false,
      json: false,
      xml: false,
    });
    networkInputStream._read = () => {
      return new Promise((resolve) => {
        return resolve(result);
      });
    };
    return networkInputStream;
  };
  
  // State result can be directly used here
  const targetInputStream = createNetworkStreamer(compound3DStructure.structure);

from ngl.

ppillot avatar ppillot commented on June 2, 2024

If I understand this correctly, the NetworkSreamer is redefined to bypass the network transfer and directly use a known file content instead.

What can be done instead is to pass a Blob containing the file content as the first argument of the stage.loadFile method.
Something like

const compound3DStructure = useAppSelector(getStructure3D);
const blob = new Blob([compound3DStructure.structure], {type: 'text/plain'});
stage.loadFile(blob, {ext: 'pdb'}).then((component: StructureComponent) => {
    // rest of the code goes there
}) 

from ngl.

FLIGHTLAMA avatar FLIGHTLAMA commented on June 2, 2024

Thank you I think we can close this.
I just described a simple case to show why I would like to override certain methods, of course there are some ways to have a workaround but that is not directly what I had in mind.

I will do the customization locally, I think that is more effective. Thanks again for your time

from ngl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.