Skip to content

Commit

Permalink
Ensure visualizer operator override
Browse files Browse the repository at this point in the history
  • Loading branch information
glopesdev committed Jul 6, 2024
1 parent 32489a7 commit 0b30c61
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
11 changes: 8 additions & 3 deletions Bonsai.Core/Reactive/Sink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.ComponentModel;
using System.Xml.Serialization;
using Bonsai.Expressions;
using System.Reflection;

namespace Bonsai.Reactive
{
Expand Down Expand Up @@ -62,13 +63,17 @@ public override Expression Build(IEnumerable<Expression> arguments)
var selector = Expression.Lambda(selectorBody, selectorParameter);
var selectorObservableType = selector.ReturnType.GetGenericArguments()[0];
return Expression.Call(
typeof(Sink), nameof(Process),
new [] { source.Type.GetGenericArguments()[0], selectorObservableType },
GetProcessMethod(source.Type.GetGenericArguments()[0], selectorObservableType),
source, selector);
});
}

static IObservable<TSource> Process<TSource, TSink>(IObservable<TSource> source, Func<IObservable<TSource>, IObservable<TSink>> sink)
internal virtual MethodInfo GetProcessMethod(params Type[] typeArguments)
{
return typeof(Sink).GetMethod(nameof(Process), BindingFlags.Static | BindingFlags.NonPublic).MakeGenericMethod(typeArguments);
}

internal static IObservable<TSource> Process<TSource, TSink>(IObservable<TSource> source, Func<IObservable<TSource>, IObservable<TSink>> sink)
{
return source.Publish(ps => MergeDependencies(ps, sink(ps).IgnoreElements().Select(xs => default(TSource))));
}
Expand Down
14 changes: 13 additions & 1 deletion Bonsai.Core/Reactive/Visualizer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.ComponentModel;
using System;
using System.ComponentModel;
using System.Reflection;
using System.Xml.Serialization;
using Bonsai.Expressions;

Expand Down Expand Up @@ -33,5 +35,15 @@ public Visualizer(ExpressionBuilderGraph workflow)
: base(workflow)
{
}

internal override MethodInfo GetProcessMethod(params Type[] typeArguments)
{
return typeof(Visualizer).GetMethod(nameof(Process), BindingFlags.Static | BindingFlags.NonPublic).MakeGenericMethod(typeArguments);
}

static new IObservable<TSource> Process<TSource, TSink>(IObservable<TSource> source, Func<IObservable<TSource>, IObservable<TSink>> sink)
{
return Sink.Process(source, sink);
}
}
}

0 comments on commit 0b30c61

Please sign in to comment.