Skip to content

Commit

Permalink
TODO added questions
Browse files Browse the repository at this point in the history
  • Loading branch information
h0lg committed Mar 15, 2024
1 parent 421e295 commit d352c2a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Fabulous/Cmd.fs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ module Cmd =
| None -> ()
| Some msg -> dispatch msg ]

//TODO what do I use this for?
/// For building Commands from the return values or exceptions of simple functions,
/// similar to a try/with or try/catch statement.
module OfFunc =
Expand Down Expand Up @@ -116,6 +117,7 @@ module Cmd =

[ bind ]

//TODO what do I use this for? Compared to other OfAsync... modules?
/// For building Commands from the return values or exceptions of Async functions,
/// similar to a try/with or try/catch statement.
module OfAsyncWith =
Expand Down Expand Up @@ -174,6 +176,7 @@ module Cmd =

[ bind >> start ]

//TODO what do I use this for? Compared to other OfAsync... modules?
/// For building Commands from Async functions started on the thread pool.
module OfAsync =
/// Command that will evaluate an async block and map the result
Expand All @@ -195,6 +198,7 @@ module Cmd =
let inline msgOption (task: Async<'msg option>) =
OfAsyncWith.performOption Async.Start (fun () -> task) () id

//TODO what do I use this for? Compared to other OfAsync... modules?
/// For building Commands from Async functions started immediately on the current operating system thread.
module OfAsyncImmediate =
/// Command that will evaluate an async block and map the result
Expand All @@ -210,6 +214,7 @@ module Cmd =
let inline attempt (task: 'a -> Async<_>) (arg: 'a) (ofError: _ -> 'msg) : Cmd<'msg> =
OfAsyncWith.attempt Async.StartImmediate task arg ofError

//TODO what do I use this for? Compared to other OfAsync... modules?
/// For building Commands from Task results.
module OfTask =
/// Command to call a task and map the results
Expand Down
19 changes: 19 additions & 0 deletions src/Fabulous/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ namespace Fabulous
open System
open System.Diagnostics

(*TODO Is either of these a program in the Elm sense? If so, where's the view in this one?
Or are these rather abstractions of or pre-cursors to an Elm Program?
AFAIU in the Elm architecture a "program" manages the application's (or component's) state, actions, and view rendering.
Please help me as a MVU/Elm newbie understand these types. *)
//TODO what's the 'arg?
/// Configuration of the Fabulous application
type Program<'arg, 'model, 'msg> =
{
Expand All @@ -21,6 +26,7 @@ type Program<'arg, 'model, 'msg> =
ExceptionHandler: exn -> bool
}

//TODO how is this different to the above? What's a 'marker? what's the 'arg?
type Program<'arg, 'model, 'msg, 'marker> =
{
State: Program<'arg, 'model, 'msg>
Expand Down Expand Up @@ -66,31 +72,44 @@ module Program =
Logger = ProgramDefaults.defaultLogger()
ExceptionHandler = ProgramDefaults.defaultExceptionHandler }

//TODO when would I use this one? How does it compare to the other stateful* builders?
//TODO what's expected for 'arg?
/// Create a program using an MVU loop
let stateful (init: 'arg -> 'model) (update: 'msg -> 'model -> 'model) =
define (fun arg -> init arg, Cmd.none) (fun msg model -> update msg model, Cmd.none)

//TODO when would I use this one? How does it compare to the other stateful* builders?
//TODO please explain the concept Cmd<'msg>
//TODO what's expected for 'arg?
/// Create a program using an MVU loop
let statefulWithCmd (init: 'arg -> 'model * Cmd<'msg>) (update: 'msg -> 'model -> 'model * Cmd<'msg>) = define init update

//TODO when would I use this one? How does it compare to the other stateful* builders?
//TODO please explain the concept CmdMsg vs. Cmd<'msg>
//TODO what's expected for 'arg?
/// <summary>
/// Create a program using an MVU loop supporting CmdMsg.
/// See also
/// <seealso href="https://elmprogramming.com/elm-architecture-conclusion.html" />
/// ?
/// </summary>
let statefulWithCmdMsg (init: 'arg -> 'model * 'cmdMsg list) (update: 'msg -> 'model -> 'model * 'cmdMsg list) (mapCmd: 'cmdMsg -> Cmd<'msg>) =
let mapCmds cmdMsgs = cmdMsgs |> List.map mapCmd |> Cmd.batch
define (fun arg -> let m, c = init arg in m, mapCmds c) (fun msg model -> let m, c = update msg model in m, mapCmds c)

(*TODO Subscriptions will be started or stopped automatically to match.
- I don't understand what that means. What (other?) Subscriptions - or - to match what?*)
/// <summary>
/// Subscribe to external source of events, overrides existing subscription.
/// Return the subscriptions that should be active based on the current model.
/// Subscriptions will be started or stopped automatically to match.
/// See also
/// <seealso href="https://elmprogramming.com/subscriptions.html" />
/// ?
/// </summary>
let withSubscription (subscribe: 'model -> Sub<'msg>) (program: Program<'arg, 'model, 'msg>) = { program with Subscribe = subscribe }

//TODO In what scenario would I want to use this?
/// Map existing subscription to external source of events.
let mapSubscription map (program: Program<'arg, 'model, 'msg>) =
{ program with
Expand Down

0 comments on commit d352c2a

Please sign in to comment.