Comments (8)
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.
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.
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.
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.
After countless attempts, I tried the code below and it worked for me:
import cxtmenu from 'cytoscape-cxtmenu';
cxtmenu.register = () => {};
from cytoscape.js-cxtmenu.
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.
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.
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.
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)
- Would it be possible to set the menuRadius based on the element size? HOT 3
- Ignored attempt to cancel a touchend event with cancelable=false HOT 2
- How to make rectangle Context menu?
- With a menu on a node, passed element is often a different empty node. HOT 4
- Displaying Menu commands based on condition HOT 4
- Support other events? HOT 1
- Context menu opens again when I click on it above a node HOT 1
- Icons not displayed for a split second when opening menu for first time HOT 2
- Contextmenu on Node/Edge and Core(Background) HOT 3
- Hover Event/Function menu items HOT 6
- CSS Variable support for fillColor and activeFillColor HOT 3
- Support for other cytoscape shapes HOT 3
- in headless testing: cy.elements().map( ele => ele.style('display')) returns object / array HOT 2
- event/function to get the position of the cxtmenu on the cytoscape graph? HOT 4
- ¿How to show menu only on node:parent ? HOT 1
- incompatible ie11 HOT 2
- Referencing to static image files HOT 1
- Why this menu is not centered on the node HOT 1
- Use application context inside commands HOT 1
- What could explain a misaligned overlay? HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cytoscape.js-cxtmenu.