jagenjo / litegraph.js

A graph node engine and editor written in Javascript similar to PD or UDK Blueprints, comes with its own editor in HTML5 Canvas2D. The engine can run client side or server side using Node. It allows to export graphs as JSONs to be included in applications independently.
MIT License
6.84k stars 719 forks source link

LGraphCanvas.onSelectionChange callback called twice #147

Open altarfinch opened 4 years ago

altarfinch commented 4 years ago

When switching selection from one node to the other, we get two events.

For example:

  1. Node 0 is selected
  2. We click on node 1
  3. We receive one event saying selection is now []
  4. We receive another event saying selection is now [1]

Is it the expected behaviour ? If you like I can modify it, that's an easy fix.

jagenjo commented 4 years ago

yes, because first you receive the deselection, and after that the selection of the new item

altarfinch commented 4 years ago

I understand that these are valid intermediate steps.

However, wouldn't it be more efficient to only trigger one event per action? Then it would be up to the developper to compare previous and new list of nodes and do the minimum modifications.

Currently, it is not possible.

If one select many nodes : [0,1,2,3,4,5,6], and then one more : [0,1,2,3,4,5,6,7].

One will get [] and then [0,1,2,3,4,5,6,7], so potentially, one will have to create new objects which one could have reused.