File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33 "isRoot" : true ,
44 "tools" : {
55 "fantomas" : {
6- "version" : " 5 .2.0 " ,
6+ "version" : " 6 .2.3 " ,
77 "commands" : [
88 " fantomas"
99 ]
Original file line number Diff line number Diff line change @@ -9,25 +9,26 @@ module CmdTestsHelper =
99 let execute dispatch ( cmd : Cmd < 'msg >) =
1010 for sub in cmd do
1111 sub dispatch
12-
12+
1313[<TestFixture>]
1414type ``Cmd tests`` () =
1515 [<Test>]
1616 member _. ``Cmd.debounce only dispatch the last message`` () =
1717 async {
1818 let mutable actualValue = None
19+
1920 let dispatch msg =
2021 if actualValue.IsNone then
2122 actualValue <- Some msg
22-
23+
2324 let triggerCmd = Cmd.debounce 100 NewValue
24-
25+
2526 triggerCmd 1 |> CmdTestsHelper.execute dispatch
2627 do ! Async.Sleep 50
2728 triggerCmd 2 |> CmdTestsHelper.execute dispatch
2829 do ! Async.Sleep 75
2930 triggerCmd 3 |> CmdTestsHelper.execute dispatch
3031 do ! Async.Sleep 125
31-
32+
3233 Assert.AreEqual( Some( NewValue 3 ), actualValue)
33- }
34+ }
Original file line number Diff line number Diff line change @@ -38,9 +38,9 @@ type WidgetBuilder<'msg, 'marker> =
3838 DebugName = $" {typeof<'marker>.Name}<{typeof<'msg>.Name}>"
3939#endif
4040 ScalarAttributes =
41- match StackList.length & scalarAttributes with
42- | 0 us -> ValueNone
43- | _ -> ValueSome( Array.sortInPlace ( fun a -> a.Key) ( StackList.toArray & scalarAttributes))
41+ match StackList.length & scalarAttributes with
42+ | 0 us -> ValueNone
43+ | _ -> ValueSome( Array.sortInPlace ( fun a -> a.Key) ( StackList.toArray & scalarAttributes))
4444
4545 WidgetAttributes = ValueOption.map ( Array.sortInPlace( fun a -> a.Key)) widgetAttributes
4646
Original file line number Diff line number Diff line change @@ -105,24 +105,23 @@ module Cmd =
105105 dispatch( failure ex)
106106 }
107107 |> ignore ]
108-
108+
109109 /// Command to issue a message if no other message has been issued within the specified timeout
110- let debounce ( timeout : int ) ( fn : 'value -> 'msg ): 'value -> Cmd < 'msg > =
110+ let debounce ( timeout : int ) ( fn : 'value -> 'msg ) : 'value -> Cmd < 'msg > =
111111 let mutable cts : CancellationTokenSource = null
112-
112+
113113 fun ( value : 'value ) ->
114114 [ fun dispatch ->
115- if cts <> null then
116- cts.Cancel()
117- cts.Dispose()
118-
119- cts <- new CancellationTokenSource()
120-
121- Async.Start(
122- async {
123- do ! Async.Sleep( timeout)
124- dispatch ( fn value)
125- },
126- cts.Token
127- )
128- ]
115+ if cts <> null then
116+ cts.Cancel()
117+ cts.Dispose()
118+
119+ cts <- new CancellationTokenSource()
120+
121+ Async.Start(
122+ async {
123+ do ! Async.Sleep( timeout)
124+ dispatch( fn value)
125+ },
126+ cts.Token
127+ ) ]
You can’t perform that action at this time.
0 commit comments