joint icon indicating copy to clipboard operation
joint copied to clipboard

Delay the binding of paper for ToolView

Open yfwz100 opened this issue 4 years ago • 8 comments

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

yfwz100 avatar Feb 05 '21 05:02 yfwz100

Hi, could you please post here an example when this is an issue?

kumilingus avatar Feb 06 '21 17:02 kumilingus

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).

yfwz100 avatar Feb 07 '21 15:02 yfwz100

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
    }

});

kumilingus avatar Feb 07 '21 17:02 kumilingus

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?

yfwz100 avatar Feb 08 '21 07:02 yfwz100

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);
  }
}

yfwz100 avatar Feb 08 '21 07:02 yfwz100

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.

github-actions[bot] avatar May 05 '22 12:05 github-actions[bot]

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.

github-actions[bot] avatar Jul 05 '22 00:07 github-actions[bot]

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.

github-actions[bot] avatar Sep 05 '22 00:09 github-actions[bot]