Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay the binding of paper for ToolView #1419

Open
yfwz100 opened this issue Feb 5, 2021 · 8 comments
Open

Delay the binding of paper for ToolView #1419

yfwz100 opened this issue Feb 5, 2021 · 8 comments

Comments

@yfwz100
Copy link
Contributor

yfwz100 commented Feb 5, 2021

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.

guard: function(evt) {
// Let the context-menu event bubble up to the relatedView
const { paper, relatedView } = this;
if (!paper || !relatedView) return true;
return paper.guard(evt, relatedView);
}

@kumilingus
Copy link
Contributor

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

@yfwz100
Copy link
Contributor Author

yfwz100 commented Feb 7, 2021

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

@kumilingus
Copy link
Contributor

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
    }

});

@yfwz100
Copy link
Contributor Author

yfwz100 commented Feb 8, 2021

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:

if (!isRendered) {
this.mount();
// Make sure tools are visible (if they were hidden and the tool removed)
this.blurTool();
this.isRendered = true;
}

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
Copy link
Contributor Author

yfwz100 commented Feb 8, 2021

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

@github-actions
Copy link

github-actions bot commented May 5, 2022

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 github-actions bot added the stale This issue/PR shows no activity for an extended period of time. label May 5, 2022
@kumilingus kumilingus added technical debt and removed stale This issue/PR shows no activity for an extended period of time. labels May 5, 2022
@github-actions
Copy link

github-actions bot commented Jul 5, 2022

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 github-actions bot added the stale This issue/PR shows no activity for an extended period of time. label Jul 5, 2022
@kumilingus kumilingus removed the stale This issue/PR shows no activity for an extended period of time. label Jul 6, 2022
@github-actions
Copy link

github-actions bot commented Sep 5, 2022

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 github-actions bot added the stale This issue/PR shows no activity for an extended period of time. label Sep 5, 2022
@jamesgeorgewilliams jamesgeorgewilliams removed the stale This issue/PR shows no activity for an extended period of time. label Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants