Giter VIP home page Giter VIP logo

Comments (4)

Ni55aN avatar Ni55aN commented on August 16, 2024

Can you share an example on codepen/jsfiddle?

from lifecycle-plugin.

janhaa avatar janhaa commented on August 16, 2024

Hi, I don't have the time to prepare one right now. Take this example code:

export default class StreamLatestComponent extends Rete.Component {
  constructor() {
    super("StreamLatest");
  }
  onconnect(io) {
  }
}

But I have two instances of StreamLatest like this:

image

When I connect something to one of the two components, the onconnect method still gets called two times, since onconnect is invoked via editor.getComponent(input.node.name).onconnect(input). From my understanding it should look for individiual nodes, something like this (probably not 100% right):

editor.on('connectioncreate', ({ input, output }) => {
    let inputNode = editor.nodes.find(node => node.id == input.node.id);
    let outputNode = editor.nodes.find(node => node.id == output.node.id);
    return inputNode.onconnect(input) === true && outputNode.onconnect(output) === true;
});

Get my point? Or am I misunderstanding something?

My current workaround is to not use the lifecycle-plugin, but to do this in the component:

builder(node) {
    this.editor.on("connectioncreate", ({ input, output }) => {
        if(input.node.id !== node.id && output.node.id !== node.id)
            return;

        /* rest of code */
    });
}

All the best!

from lifecycle-plugin.

Ni55aN avatar Ni55aN commented on August 16, 2024

onconnect method still gets called two times

This is the expected behavior, since onconnect is called for Input and Output of two nodes you connect

from lifecycle-plugin.

janhaa avatar janhaa commented on August 16, 2024

Yeah I see, I re-thought this and see how your design was intended now. :) Cheers!

from lifecycle-plugin.

Related Issues (4)

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.