Skip to content

Commit

Permalink
refactor event constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
colombod committed Sep 8, 2021
1 parent e66a05a commit 309fb71
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,7 @@ IEnumerable<KernelEvent> events()

yield return new ValueNamesProduced(new[] { "a", "b", "c" }, new RequestValueNames("csharp"));

yield return new ValueProduced("raw value", "a",
new RequestValue("a", "csharp", HtmlFormatter.MimeType ), new FormattedValue(HtmlFormatter.MimeType, "<span>formatted value</span>"));
yield return new ValueProduced("raw value", "a", new FormattedValue(HtmlFormatter.MimeType, "<span>formatted value</span>"), new RequestValue("a", "csharp", HtmlFormatter.MimeType ));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.DotNet.Interactive/Commands/RequestValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ public override Task InvokeAsync(KernelInvocationContext context)
using var writer = new StringWriter(CultureInfo.InvariantCulture);
formatter.Format(value, writer);
var formatted = new FormattedValue(mimeType, writer.ToString());
context.Publish(new ValueProduced(value, Name, this, formatted));
context.Publish(new ValueProduced(value, Name, formatted, this));
}
else
{
var mimeType = MimeType ?? Formatter.GetPreferredMimeTypeFor(typeof(object));
var formatted = new FormattedValue(mimeType, "null");

context.Publish(new ValueProduced(value, Name, this, formatted));
context.Publish(new ValueProduced(value, Name, formatted, this));
}

return Task.CompletedTask;
Expand Down
7 changes: 3 additions & 4 deletions src/Microsoft.DotNet.Interactive/Events/ValueProduced.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Microsoft.DotNet.Interactive.Commands;

Expand All @@ -18,8 +17,8 @@ public class ValueProduced : KernelEvent

public ValueProduced(object value,
string name,
RequestValue command,
FormattedValue formattedValue = null) : base(command)
FormattedValue formattedValue,
RequestValue command) : base(command)
{
if (string.IsNullOrWhiteSpace(name))
{
Expand All @@ -28,7 +27,7 @@ public ValueProduced(object value,

Value = value;
Name = name;
FormattedValue = formattedValue;
FormattedValue = formattedValue ?? throw new ArgumentNullException(nameof(formattedValue));
}
}
}

0 comments on commit 309fb71

Please sign in to comment.