Giter VIP home page Giter VIP logo

lifecycle-plugin's Introduction

Lifecycle

Rete.js plugin

import LifecyclePlugin from 'rete-lifecycle-plugin';

editor.use(LifecyclePlugin);


class AddComponent extends Rete.Component {
    constructor(){
        super("Add");
    }

    created(node) {
    }

    destroyed(node) {
    }

    onconnect(io) { // input or output
        return false; // prevent connect
    }

    ondisconnect(connection) {
        return false; // prevent disconnect
    }

    connected(connection) {
    }

    disconnected(connection) {
    }
}

TypeScript

import { OnCreated, OnDestroyed, OnConnect, OnConnected, OnDisconnect, OnDisconnected } from 'rete-lifecycle-plugin';

class AddComponent extends Rete.Component implements OnCreated, ...

lifecycle-plugin's People

Contributors

dependabot[bot] avatar ni55an avatar

Watchers

 avatar  avatar  avatar

lifecycle-plugin's Issues

`this` is not pointing at instance of called class

this is not bound in created and destroyed, so it's hard to access custom context variables:

export class TestComponent extends Rete.Component {
  constructor(foo) {
    super("Test");
    this.foo = foo;
  }
  created(node) {
    console.log(`Created ${node.id} for ${this.foo}`); // Won't work, because `this` will be `undefined`
  }
}

The function hooks should be bound to the respective class instance.


Background

In my particular use-case, I'd like to have a context variable (equivalent to foo) point at a container DOM element and each node owns a DOM child that is attached to the container DOM element. However, during node creation / destruction I'm unable to find the container DOM element, because this is undefined.

Components should not be selected only by name

Currently, the methods are triggered by selecting a node through its name. But if you have multiple instances of one type of node, the methods are called for all of these, which is unexpected behaviour.

Talking about this:
editor.getComponent(input.node.name)

Might submit a PR soon.

Methods are not ran in modules

When combined with https://github.com/retejs/module-plugin the components inside the module won't receive calls for create / destroy. This makes sense if the created / destroyed is only meant for visible nodes.

However, it also doesn't seem to be possible to do engine.use(LifecyclePlugin) either (to get a callback for each data-processing node, regardless of the node origin).

So where would one do the initialization and destruction of per-node data for specific components?

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.