Git Product home page Git Product logo

Comments (8)

mirkolenz avatar mirkolenz commented on June 11, 2024 4

For me, the following worked:

import cytoscape from "cytoscape";
import cxtmenu from "cytoscape-cxtmenu";

cytoscape.use(cxtmenu);
// eventually other calls to cytoscape.use()
cytoscape.use = () => {};

from cytoscape.js-cxtmenu.

jri avatar jri commented on June 11, 2024 3

Meanwhile I investigated it further and found I was wrong here:

The Cytoscape instance seems corrupted somehow then.
Possibly this is because setExtension() terminates early, returning the result of overrideErr() instead the extensions map (but I'm not sure about this).

Actually it's due to my application, not Cytoscape, that the canvas is not rendered when hot replaced.
Sorry for bothering you.

But still, Cytoscape reports the console message as an error, not as a warning which I can safely ignore. That gave me the (wrong) impression the problem is in Cytoscape.

screen shot 2018-01-21 at 13 33 04

Cytoscape should display that console message as a warning, not as an error.
That would have avoided the entire misunderstanding in the first place.

And still I think an explicit unregister Core call is desired.
This way the overrideErr could be prevented in the first place.

Thank you for the support!

from cytoscape.js-cxtmenu.

sirbris avatar sirbris commented on June 11, 2024 2

I get the same error "Can not register cxtmenu for core since cxtmenu already exists in the prototype..." but am not able to check, if cxtmenu was already registered.
Setting "Object.getPrototypeOf( cy )[ cxtmenu ] = null;" before did not work.

How can I avoid this registration here if it has been done already?
cytoscape.use(cxtmenu);

Thank you very much in advance!

from cytoscape.js-cxtmenu.

marcosalpereira avatar marcosalpereira commented on June 11, 2024 1

After countless attempts, I tried the code below and it worked for me:

import cxtmenu from 'cytoscape-cxtmenu';
cxtmenu.register = () => {};

from cytoscape.js-cxtmenu.

maxkfranz avatar maxkfranz commented on June 11, 2024

There would have to be a new core function for that. An extension doesn't modify anything; it just requests the core to do so.

Anyway, I don't think that message should give you any problems. It's just a console message, not an exception. So, it shouldn't prevent your code from progressing either way.

from cytoscape.js-cxtmenu.

jri avatar jri commented on June 11, 2024

Anyway, I don't think that message should give you any problems. It's just a console message, not an exception. So, it shouldn't prevent your code from progressing either way.

Unfortunately I can't acknowledge that.

When my application's rendering (vue) component is hot replaced (by webpack-dev-server) the cxtmenu extension is registered again, which fails.
No graph rendering takes place then. The canvas remains empty.

The Cytoscape instance seems corrupted somehow then.
Possibly this is because setExtension() terminates early, returning the result of overrideErr() instead the extensions map (but I'm not sure about this).

function setExtension(type, name, registrant) {

  var ext = registrant;

  var overrideErr = function overrideErr(field) {
    util.error('Can not register `' + name + '` for `' + type + '` since `' + field + '` already exists in the prototype and can not be overridden');
  };

  if (type === 'core') {
    if (Core.prototype[name]) {
      return overrideErr(name);
    } else {
      Core.prototype[name] = registrant;
    }
  } else if
     ...
  }

  return util.setMap({
    map: extensions,
    keys: [type, name],
    value: ext
  });
}

In conjunction with hot module replacement the double extension registration occurs because of this: when hot replaced my renderer component creates a new Cytoscape instance. On the other hand the Cytoscape modules itself are not replaced. The state of Core.prototype remains intact, and causes the override error.

With browser reload the application works fine again, but this removes the benefit of hot module replacement.

In order to work with hot module replacement Cytoscape Core should provide an explicit unregister call.

from cytoscape.js-cxtmenu.

maxkfranz avatar maxkfranz commented on June 11, 2024

I agree it would be nice to have something to unregister extensions, but there are important issues that would need to be addressed.

An extension can register many fields on the prototype. A foo extension could register cy.foo() and cy.bar(), for example. Well behaved extensions would only use cy.foo() or ele.foo(), so we'd have to decide whether to only support those extensions or whether to automatically listen for individual prototype registrations within a cytoscape.use() call. The automatic case wouldn't work if you had an extension that itself registered and used another extension. In any case, this gives you some idea of the sorts of considerations that would have to be made before making new cytoscape.unuse() API.

Edit: For now, you could just rig getPrototypeOf( cy )[ extensionName ] = null before you (re)register.

Warnings are already addressed for 3.3: cytoscape/cytoscape.js#2021

All errors that would block expected behaviour throw, and non-blocking ones are demoted to console.warn()ings.

from cytoscape.js-cxtmenu.

stale avatar stale commented on June 11, 2024

This issue has been automatically marked as stale, because it has not had activity within the past 30 days. It will be closed if no further activity occurs within the next 30 days. If a feature request is important to you, please consider making a pull request. Thank you for your contributions.

from cytoscape.js-cxtmenu.

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.