Skip to content

Commit b65e6dd

Browse files
committed
CSharp -- Fix various TODO's
1 parent 71840c5 commit b65e6dd

File tree

10 files changed

+62
-183
lines changed

10 files changed

+62
-183
lines changed

Diff for: Dash.NET.CSharp.Giraffe/DashAppCSharp.fs

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ type DashGiraffeConfig =
1414
{
1515
HostName : string
1616
LogLevel : LogLevel
17-
ErrorHandler : System.Func<System.Exception,HttpHandler> // TODO : HttpHandler type from C# is not very usable
17+
// NOTE (giraffe HttpHandler) : The F# version takes a function that returns an HttpHandler type (a type from the Giraffe library). For new we decided to keep C# simpler and just return strings on error, since giraffe stuff is awkward to use from C#.
18+
ErrorHandler : System.Func<System.Exception,string>
1819
IpAddress: string
1920
Port : int
2021
}
2122
with static member internal convertConfig (config : DashGiraffeConfig) : Dash.NET.Giraffe.DashGiraffeConfig =
2223
{
2324
Dash.NET.Giraffe.DashGiraffeConfig.HostName = config.HostName
2425
LogLevel = config.LogLevel
25-
ErrorHandler = FuncConvert.FromFunc(config.ErrorHandler)
26+
ErrorHandler = fun ex -> ex |> FuncConvert.FromFunc(config.ErrorHandler) |> Core.text // See: NOTE (giraffe HttpHandler)
2627
IpAddress = config.IpAddress
2728
Port = config.Port
2829
}

Diff for: Dash.NET.CSharp/Callback.fs

-65
Original file line numberDiff line numberDiff line change
@@ -33,71 +33,6 @@ type Callback = private WrappedCallback of Dash.NET.Callback<obj> with
3333

3434
static member Unwrap (v) = match v with | WrappedCallback v -> v // Can't be internal because accessed by Dash.NET.CSharp.Giraffe
3535

36-
///// <summary>returns a callback that binds a handler function mapping from multiple input components to a single output component (n -> 1)</summary>
37-
///// <param name="input"> A sequence of `CallbackInput` that represents the input components of this callback. Changes to any of these components signalled by the client will trigger the callback. </param>
38-
///// <param name="output"> A `CallbackOutput` that represents the output component of this callback </param>
39-
///// <param name="handler"> The handler function that maps the callback input components to the callback output components </param>
40-
///// <param name="state"> A sequence of `CallbackState` that represents additional input components of this callback. In contrast to the other input componenst, these will not trigger the handler function when changed on the client.</param>
41-
///// <param name="preventInitialCall"> Wether to prevent the app to call this callback on initialization </param>
42-
///// <param name="clientSideFunction"> A client side function to execute with the callback </param>
43-
//static member Create
44-
// (
45-
// input : Dependency array,
46-
// output : Dependency array,
47-
// handler: System.Func<'a, CallbackResult array>,
48-
// [<Optional>] state : Dependency array,
49-
// [<Optional>] preventInitialCall : System.Nullable<bool>,
50-
// [<Optional>] clientSideFunction : Dash.NET.ClientSideFunction // TODO
51-
// ) : Callback =
52-
// guardAgainstNull "input" input
53-
// guardAgainstNull "output" output
54-
// guardAgainstNull "handler" handler
55-
56-
// let state = Option.ofObj state |> Option.map (Array.map Helpers.ConvertDependency >> Seq.ofArray)
57-
// let preventInitialCall = Option.ofNullable preventInitialCall
58-
// let clientSideFunction : Dash.NET.ClientSideFunction option = Option.ofObj (box clientSideFunction) |> unbox
59-
60-
// let handlerFunction = fun a -> (FuncConvert.FromFunc handler) a |> List.ofArray |> List.map CallbackResult.Unwrap
61-
62-
// Dash.NET.Callback.multiOut(
63-
// input |> Array.map Helpers.ConvertDependency,
64-
// output |> Array.map Helpers.ConvertDependency,
65-
// box handlerFunction,
66-
// ?State = state,
67-
// ?PreventInitialCall = preventInitialCall,
68-
// ?ClientSideFunction = clientSideFunction
69-
// )
70-
// |> WrappedCallback
71-
72-
//static member Create
73-
// (
74-
// input : Dependency array,
75-
// output : Dependency array,
76-
// handler: System.Func<'a, 'b, CallbackResult array>,
77-
// [<Optional>] state : Dependency array,
78-
// [<Optional>] preventInitialCall : System.Nullable<bool>,
79-
// [<Optional>] clientSideFunction : Dash.NET.ClientSideFunction // TODO
80-
// ) : Callback =
81-
// guardAgainstNull "input" input
82-
// guardAgainstNull "output" output
83-
// guardAgainstNull "handlerFunction" handler
84-
85-
// let state = Option.ofObj state |> Option.map (Array.map Helpers.ConvertDependency >> Seq.ofArray)
86-
// let preventInitialCall = Option.ofNullable preventInitialCall
87-
// let clientSideFunction : Dash.NET.ClientSideFunction option = Option.ofObj (box clientSideFunction) |> unbox
88-
89-
// let handlerFunction = fun a b -> (FuncConvert.FromFunc handler) a b |> List.ofArray |> List.map CallbackResult.Unwrap
90-
91-
// Dash.NET.Callback.multiOut(
92-
// input |> Array.map Helpers.ConvertDependency,
93-
// output |> Array.map Helpers.ConvertDependency,
94-
// box handlerFunction,
95-
// ?State = state,
96-
// ?PreventInitialCall = preventInitialCall,
97-
// ?ClientSideFunction = clientSideFunction
98-
// )
99-
// |> WrappedCallback
100-
10136
/// <summary>returns a callback that binds a handler function mapping from multiple input components to a single output component (n -> 1)</summary>
10237
/// <param name="input"> A sequence of `CallbackInput` that represents the input components of this callback. Changes to any of these components signalled by the client will trigger the callback. </param>
10338
/// <param name="output"> A `CallbackOutput` that represents the output component of this callback </param>

Diff for: Dash.NET.Giraffe.CSharp.Example/Program.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using Dash.NET.CSharp.DCC;
33
using Plotly.NET;
4-
using Giraffe;
54
using System.Collections.Generic;
65
using Microsoft.Extensions.Logging;
76
using static Dash.NET.CSharp.Dsl;
@@ -142,7 +141,7 @@ static void Main(string[] args)
142141
logLevel: LogLevel.Debug,
143142
ipAddress: "*",
144143
port: 8000,
145-
errorHandler: (Exception err) => Core.text(err.Message)
144+
errorHandler: (Exception err) => err.Message
146145
);
147146

148147
dashApp.run(

Diff for: Dash.NET.Giraffe.CSharp.Tests/Layout_FirstExample.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using static Dash.NET.CSharp.Dsl;
99
using Plotly.NET;
1010
using Microsoft.Extensions.Logging;
11-
using Giraffe;
1211

1312
namespace Documentation.Examples
1413
{
@@ -47,7 +46,7 @@ public static void RunExample()
4746
logLevel: LogLevel.Debug,
4847
ipAddress: "*",
4948
port: 49246,
50-
errorHandler: (Exception err) => Core.text(err.Message)
49+
errorHandler: (Exception err) => err.Message
5150
);
5251

5352
dashApp.run(

Diff for: Dash.NET.Giraffe.CSharp.Tests/Layout_Markdown.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Dash.NET.CSharp.DCC;
22
using Dash.NET.CSharp.Giraffe;
3-
using Giraffe;
43
using Microsoft.Extensions.Logging;
54
using System;
65
using System.Collections.Generic;
@@ -35,7 +34,7 @@ public static void RunExample()
3534
logLevel: LogLevel.Debug,
3635
ipAddress: "*",
3736
port: 8000,
38-
errorHandler: (Exception err) => Core.text(err.Message)
37+
errorHandler: (Exception err) => err.Message
3938
);
4039

4140
dashApp.run(

Diff for: Dash.NET.Giraffe.CSharp.Tests/Layout_MoreAboutHtmlComponents.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using static Dash.NET.CSharp.Dsl;
99
using Plotly.NET;
1010
using Microsoft.Extensions.Logging;
11-
using Giraffe;
1211

1312
namespace Documentation.Examples
1413
{
@@ -70,7 +69,7 @@ public static void RunExample()
7069
logLevel: LogLevel.Debug,
7170
ipAddress: "*",
7271
port: 49246,
73-
errorHandler: (Exception err) => Core.text(err.Message)
72+
errorHandler: (Exception err) => err.Message
7473
);
7574

7675
dashApp.run(

Diff for: Dash.NET.Giraffe.CSharp.Tests/Layout_ReusableComponents.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using Giraffe;
32
using System.Collections.Generic;
43
using Microsoft.Extensions.Logging;
54
using static Dash.NET.CSharp.Dsl;
@@ -56,7 +55,7 @@ public static void RunExample()
5655
logLevel: LogLevel.Debug,
5756
ipAddress: "*",
5857
port: 8000,
59-
errorHandler: (Exception err) => Core.text(err.Message)
58+
errorHandler: (Exception err) => err.Message
6059
);
6160

6261
dashApp.run(

Diff for: Dash.NET.Giraffe.CSharp.Tests/Template_Example.cs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using static Dash.NET.CSharp.Dsl;
99
using Plotly.NET;
1010
using Microsoft.Extensions.Logging;
11-
using Giraffe;
1211

1312
namespace Documentation.Examples
1413
{

Diff for: dev/Program.fs

+1-54
Original file line numberDiff line numberDiff line change
@@ -97,58 +97,6 @@ let callbackArrayInput =
9797
]
9898
)
9999

100-
(* ---- START : TEMP TEST ---- *)
101-
102-
// TODO : Can't resolve overloads based on 'just' tuples. Need to wrap arguments in 'Input' single case DU.
103-
// // Test 2 inputs :
104-
//let callbackArrayInputV2 =
105-
// {
106-
// Inputs = CallbackDependency.Create<float array, float>(("testInput1", Value), ("testInput2", N_Clicks))
107-
// Outputs = CallbackDependency.Create<float, float>(("output-1", Children), ("output-2", Children))
108-
// Handler =
109-
// CallbackHandler.Create(
110-
// fun (inputs, clicks) ->
111-
// let nclicks = 10.
112-
// CallbackResult.Create(
113-
// ((Array.last inputs) * nclicks * 1.),
114-
// ((Array.last inputs) * nclicks * 2.)
115-
// )
116-
// )
117-
118-
// }
119-
120-
// WORKS :
121-
let callbackArrayInputV2 =
122-
{
123-
Inputs = CallbackDependency.Create<float array>(("testInput1", Value))
124-
Outputs = CallbackDependency.Create<float, float>(("output-1", Children), ("output-2", Children))
125-
Handler =
126-
CallbackHandler.Create(
127-
fun inputs ->
128-
let nclicks = 10.
129-
CallbackResult.Create(
130-
((Array.last inputs) * nclicks * 1.),
131-
((Array.last inputs) * nclicks * 2.)
132-
)
133-
)
134-
135-
}
136-
137-
//let callbackArrayInputV2 =
138-
// {
139-
// Inputs = CallbackDependency.Create<float array>(("testInput1", Value))
140-
// Outputs = CallbackDependency.Create<float, float>(("output-1", Children), ("output-2", Children))
141-
// Handler =
142-
// fun (inputs) ->
143-
// let nclicks = 10.
144-
// CallbackResult.Create(
145-
// ((Array.last inputs) * nclicks * 1.),
146-
// ((Array.last inputs) * nclicks * 1.)
147-
// )
148-
// }
149-
150-
(* ---- END : TEMP TEST ---- *)
151-
152100
// usage of the new operators:
153101
let clickInput =
154102
Callback.singleOut (
@@ -171,8 +119,7 @@ let myDashApp =
171119
"main.css" // serve your custom css
172120
"https://cdnjs.cloudflare.com/ajax/libs/bulma/0.9.1/css/bulma.min.css" // register bulma as an external css dependency
173121
]
174-
//|> DashApp.addCallback callbackArrayInput // register the callback that will update the map
175-
|> DashApp.addCallback (CallbackV2.ToCallback callbackArrayInputV2) // register the callback that will update the map
122+
|> DashApp.addCallback callbackArrayInput // register the callback that will update the map
176123
|> DashApp.addCallback clickInput // register the callback that will update the map
177124

178125

0 commit comments

Comments
 (0)