joint
joint copied to clipboard
Delay the binding of paper for ToolView
See the code below. The paper
binding could be derived from relatedView
instead of binding directly. By delaying the binding of paper, the ToolView
could be initialized within the initialization procedure of Link
.
https://github.com/clientIO/joint/blob/7b6080dfa3643323cf1553f9049d6845fe951055/src/dia/ToolView.mjs#L62-L67
Hi, could you please post here an example when this is an issue?
It's a structural issue rather than a functional issue. In my opinnion, link tools are attachments to links so they should be subject to links instead of papers. Therefore, I tried to encapsulate the link tools into links' constructor(initialize) but found that it failed without any errors (the guard method always returns true if paper is null or undefined).
I see. Would this help for the time being?
Object.defineProperty(joint.dia.ToolView.prototype, 'paper', {
enumerable: true,
get: function() {
return this.relatedView.paper;
},
set: function() {
// noop
}
});
This polyfill works. However, there's another issue. If I put link tools in links' constructor, the link tools are always shown at the first time.
I further found the following code:
https://github.com/clientIO/joint/blob/68481bcb9964c809a3614d3093ccd921a0b0b4ef/src/dia/ToolsView.mjs#L57-L62
If the link tools are rendered the first time, it's always visible.
At present, I use a setTimeout()
to delay the binding of link tools but it seems unreliable. Is there a correct phase to hide the link tools?
Extending the ToolsView
can get around this issue but it's a bit ugly...
class MyToolsView extends joint.dia.ToolsView {
get paper() {
return this.relatedView.paper;
}
blurTool(...args) {
if (!this.isRendered) {
return; // do nothing.
}
super.blurTool(...args);
}
}
This issue is stale because it has been open 60 days with no activity. Please remove stale label or comment or this will be closed in 14 days.
This issue is stale because it has been open 60 days with no activity. Please remove stale label or comment or this will be closed in 14 days.
This issue is stale because it has been open 60 days with no activity. Please remove stale label or comment or this will be closed in 14 days.