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

Validation Inifinite Loop when cascading values through nodes #105

Open
rooper149 opened this issue Mar 4, 2021 · 2 comments
Open

Validation Inifinite Loop when cascading values through nodes #105

rooper149 opened this issue Mar 4, 2021 · 2 comments
Labels

Comments

@rooper149
Copy link

If you create a node that basically passes an input to an output it seems you can get yourself stuck in a loop that has something to do with validation. For instance in this code: if you connect Node A's output to Node B's input everything is fine, but if you then disconnect those two nodes and instead connect Node B's output to Node A's input you get stuck in a loop and the UI becomes unresponsive. Is this a known constraint/issue, or am I missing something?

public class Test : NodeViewModel
    {
        public ValueNodeInputViewModel<string> Input { get; }
        public ValueNodeOutputViewModel<string> Output { get; }

        static Test()
        {
            Splat.Locator.CurrentMutable.Register(() => new NodeView(), typeof(IViewFor<Test>));
        }

        public Test(string name)
        {
            Name = name;

            Input = new ValueNodeInputViewModel<string>()
            {
                Name = "Input"
            };
            Inputs.Add(Input);

            Output = new ValueNodeOutputViewModel<string>()
            {
                Name = "Output",
                Value = this.WhenAnyObservable(vm => vm.Input.ValueChanged)
            };
            Outputs.Add(Output);
        }
    }

    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            var network = new NetworkViewModel();

            var test = new Test(@"Node A");
            network.Nodes.Add(test);

            var test2 = new Test(@"Node B");
            network.Nodes.Add(test2);  
            
            networkView.ViewModel = network;
        }
    }
@Wouterdek
Copy link
Owner

That's a bug, thanks for the example code.

@Wouterdek Wouterdek added the bug label Mar 5, 2021
@Wouterdek
Copy link
Owner

Wouterdek commented Mar 5, 2021

I'll look more into this later. An easy way to fix this is to replace

Value = this.WhenAnyObservable(vm => vm.Input.ValueChanged)

with

Value = this.WhenAnyValue(vm => vm.Input.Value)

or

Value = this.WhenAnyObservable(vm => vm.Input.ValueChanged).Distinct()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants