Skip to content

Commit eee3c51

Browse files
committed
Testing JsInterop performance
1 parent 51a7a9b commit eee3c51

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

docs/BlazorApexCharts.Docs/Components/Features/Performance/Basic.razor

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
@using System.Diagnostics
22
@using System.Text.Json
33

4-
<Checkbox Switch @bind-Value=unMarshalledJS Label="Use UnMarshalledJS" />
4+
5+
6+
<ItemSelect Label="JS Interop Strategy" Items="@(EnumHelper.GetList<JSInteropStrategy>())" @bind-SelectedValue="@jsInteropStrategy" Changed=LoadData/>
57

68
<ItemSelect Label="Datapoints" Items=points @bind-SelectedValue=pointsToLoad Changed=LoadData />
79

@@ -10,7 +12,7 @@
1012
Title="Value"
1113
Height="150"
1214
XAxisType="XAxisType.Datetime"
13-
UnMarshalledJS=unMarshalledJS
15+
JSInteropStrategy=jsInteropStrategy
1416
@ref=chart>
1517

1618

@@ -35,7 +37,7 @@ else
3537

3638

3739
@code {
38-
private bool unMarshalledJS = true;
40+
private JSInteropStrategy jsInteropStrategy = JSInteropStrategy.UnMarshalled;
3941
private ApexChart<TimeSeries> chart;
4042
private List<int> points = new List<int> { 100, 1000, 5000, 10000 };
4143
private int pointsToLoad = 100;

src/Blazor-ApexCharts/ApexChart.razor.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public partial class ApexChart<TItem> : IDisposable where TItem : class
2020
[Parameter] public string Title { get; set; }
2121
[Parameter] public XAxisType? XAxisType { get; set; }
2222
[Parameter] public bool Debug { get; set; }
23-
[Parameter] public bool UnMarshalledJS { get; set; }
23+
[Parameter] public JSInteropStrategy JSInteropStrategy { get; set; }
2424
[Parameter] public object Width { get; set; }
2525
[Parameter] public object Height { get; set; }
2626
[Parameter] public EventCallback<SelectedData<TItem>> OnDataPointSelection { get; set; }
@@ -365,16 +365,16 @@ public async Task UpdateSeriesAsync(bool animate = true)
365365
Console.WriteLine($"Serialize {sw.ElapsedMilliseconds}");
366366

367367

368-
if (jsUnmarshalled != null && UnMarshalledJS)
368+
if (jsUnmarshalled != null && JSInteropStrategy == JSInteropStrategy.UnMarshalled)
369369
{
370370
jsUnmarshalled.InvokeUnmarshalled<string, string, string, string>("blazor_apexchart.testUnmarshalled", Options.Chart.Id, jsonSeries, animate.ToString().ToLower());
371-
Console.WriteLine($"Invoke InvokeUnmarshalled {sw.ElapsedMilliseconds}");
371+
Console.WriteLine($"Invoke Unmarshalled {sw.ElapsedMilliseconds}");
372372

373373
}
374-
else if (jsInprocess != null)
374+
else if (jsInprocess != null && JSInteropStrategy == JSInteropStrategy.Sync)
375375
{
376376
jsInprocess.InvokeVoid("blazor_apexchart.updateSeries", Options.Chart.Id, jsonSeries, animate);
377-
Console.WriteLine($"Invoke Void {sw.ElapsedMilliseconds}");
377+
Console.WriteLine($"Invoke Sync {sw.ElapsedMilliseconds}");
378378

379379
}
380380
else
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+

2+
namespace ApexCharts
3+
{
4+
public enum JSInteropStrategy
5+
{
6+
UnMarshalled = 0,
7+
Sync = 1,
8+
Async = 2
9+
}
10+
}

src/Blazor-ApexCharts/wwwroot/js/blazor-apex-charts.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
window.blazor_apexchart = {
22

33
testUnmarshalled(id, series, animate) {
4-
//const chartId = BINDING.conv_string(id);
5-
//const data = BINDING.conv_string(series);
6-
//const animateString = BINDING.conv_string(animate);
7-
84
var chartAnimate = (BINDING.conv_string(animate).toLowerCase() === 'true');
9-
105
this.updateSeries(BINDING.conv_string(id), BINDING.conv_string(series), chartAnimate);
116
},
127

0 commit comments

Comments
 (0)