Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
TimLariviere committed Nov 25, 2023
1 parent a5a74a1 commit 9a0acf6
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 55 deletions.
15 changes: 4 additions & 11 deletions samples/Components/HelloComponent/App.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,10 @@ open Microsoft.Maui.Hosting
open type Fabulous.Maui.View

module App =
let view() =
Component() {
Application(
ContentPage(
Label("Hello from Fabulous for Maui with components!")
.center()
)
)
}

let createMauiApp() =
let view () =
Component() { Application(ContentPage(Label("Hello from Fabulous for Maui with components!").center())) }

let createMauiApp () =
MauiApp
.CreateBuilder()
.UseFabulousApp(view())
Expand Down
39 changes: 20 additions & 19 deletions samples/Components/MultipleMvus/App.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,56 @@ open type Fabulous.Maui.View

module Counter =
type Model = { Count: int }
type Msg = Increment | Decrement

let init() = { Count = 0 }


type Msg =
| Increment
| Decrement

let init () = { Count = 0 }

let update msg model =
match msg with
| Increment -> { Count = model.Count + 1 }
| Decrement -> { Count = model.Count - 1 }

let program = Program.ForComponent.stateful init update

module Form =
type Model =
{ FirstName: string
LastName: string }

type Model = { FirstName: string; LastName: string }

type Msg =
| FirstNameChanged of string
| LastNameChanged of string
let init() = { FirstName = ""; LastName = "" }

let init () = { FirstName = ""; LastName = "" }

let update msg model =
match msg with
| FirstNameChanged s -> { model with FirstName = s }
| LastNameChanged s -> { model with LastName = s }

let program = Program.ForComponent.stateful init update

module App =
let view() =
let view () =
Application() {
ContentPage() {
(VStack(spacing = 25.) {
Label("App")

MvuComponent(Counter.program) {
let! model = Mvu.State

VStack() {
Label($"Count = {model.Count}")
Button("Increment", Counter.Increment)
Button("Decrement", Counter.Decrement)
}
}

MvuComponent(Form.program) {
let! model = Mvu.State

VStack() {
Label($"Hello {model.FirstName} {model.LastName}")
Entry(model.FirstName, Form.FirstNameChanged)
Expand Down
6 changes: 3 additions & 3 deletions samples/Components/MvuCounter/App.fs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ module App =
timerCmd()
else
model, Cmd.none

let program = Program.ForComponent.statefulWithCmd init update

let view() =
let view () =
MvuComponent(program) {
let! model = Mvu.State

Application() {
ContentPage() {
(VStack() {
Expand Down
10 changes: 5 additions & 5 deletions samples/Components/SimpleCounter/App.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ module App =
let view =
Component() {
let! count = State(0)

Application(
ContentPage(
(VStack() {
Label($"%d{count.Current}").centerTextHorizontal()
Button("Increment", fun () -> count.Set(count.Current + 1))
Button("Decrement", fun () -> count.Set(count.Current - 1))
Button("Increment", (fun () -> count.Set(count.Current + 1)))
Button("Decrement", (fun () -> count.Set(count.Current - 1)))
})
.center()
)
)
}
let createMauiApp() =

let createMauiApp () =
MauiApp
.CreateBuilder()
.UseFabulousApp(view)
Expand Down
6 changes: 3 additions & 3 deletions samples/Components/TicTacComponent/App.fs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ module App =
/// The visual contents of a cell depends on this condition.
let canPlay model cell =
(cell = Empty) && (getGameResult model = StillPlaying)

let program =
Program.ForComponent.stateful init update
|> Program.ForComponent.withSubscription(fun _ ->
Expand All @@ -203,7 +203,7 @@ module App =
let view () =
MvuComponent(program) {
let! model = Mvu.State

Application(
ContentPage(
Grid(coldefs = [ Star ], rowdefs = [ Star; Auto; Auto ]) {
Expand Down Expand Up @@ -263,4 +263,4 @@ module App =
}
)
)
}
}
5 changes: 3 additions & 2 deletions src/Fabulous.MauiControls/Component.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ module Component =
[<AutoOpen>]
module ComponentBuilders =
type Fabulous.Maui.View with

static member inline Component<'marker>() = ComponentBuilder()

static member inline MvuComponent(program: Program<unit, 'model, 'msg>) = MvuComponentBuilder(program, ())

static member inline MvuComponent(program: Program<'arg, 'model, 'msg>, arg: 'arg) = MvuComponentBuilder(program, arg)
17 changes: 11 additions & 6 deletions src/Fabulous.MauiControls/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,23 @@ module MauiViewHelpers =
| _ -> true

module Program =
let inline private define (view: 'model -> WidgetBuilder<'msg, 'marker>) (program: Program<'arg, 'model, 'msg>): Program<'arg, 'model, 'msg, 'marker> =
let inline private define (view: 'model -> WidgetBuilder<'msg, 'marker>) (program: Program<'arg, 'model, 'msg>) : Program<'arg, 'model, 'msg, 'marker> =
{ Program = program
View = view
CanReuseView = MauiViewHelpers.canReuseView
SyncAction = MainThread.BeginInvokeOnMainThread }

/// Create a program for a static view
let stateless (view: unit -> WidgetBuilder<unit, 'marker>) =
let program = Program.ForComponent.define (fun () -> (), Cmd.none) (fun () () -> (), Cmd.none)
let program =
Program.ForComponent.define (fun () -> (), Cmd.none) (fun () () -> (), Cmd.none)

define view program

/// Create a program using an MVU loop
let stateful (init: 'arg -> 'model) (update: 'msg -> 'model -> 'model) (view: 'model -> WidgetBuilder<'msg, 'marker>) =
define view (Program.ForComponent.stateful init update)

/// Create a program using an MVU loop. Add support for Cmd
let statefulWithCmd
(init: 'arg -> 'model * Cmd<'msg>)
Expand Down Expand Up @@ -119,11 +121,13 @@ module Program =
/// Subscribe to external source of events.
/// The subscription is called once - with the initial model, but can dispatch new messages at any time.
let withSubscription (subscribe: 'model -> Cmd<'msg>) (program: Program<'arg, 'model, 'msg, 'marker>) =
{ program with Program = Program.ForComponent.withSubscription subscribe program.Program }
{ program with
Program = Program.ForComponent.withSubscription subscribe program.Program }

/// Configure how the output messages from Fabulous will be handled
let withLogger (logger: Logger) (program: Program<'arg, 'model, 'msg, 'marker>) =
{ program with Program = Program.ForComponent.withLogger logger program.Program }
{ program with
Program = Program.ForComponent.withLogger logger program.Program }

/// Trace all the updates to the debug output
let withTrace (trace: string * string -> unit) (program: Program<'arg, 'model, 'msg, 'marker>) =
Expand All @@ -144,7 +148,8 @@ module Program =

/// Configure how the unhandled exceptions happening during the execution of a Fabulous app with be handled
let withExceptionHandler (handler: exn -> bool) (program: Program<'arg, 'model, 'msg, 'marker>) =
{ program with Program = Program.ForComponent.withExceptionHandler handler program.Program }
{ program with
Program = Program.ForComponent.withExceptionHandler handler program.Program }

/// Allow the app to react to theme changes
let withThemeAwareness (program: Program<'arg, 'model, 'msg, #IFabApplication>) =
Expand Down
9 changes: 3 additions & 6 deletions src/Fabulous.MauiControls/Views/Application.fs
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,9 @@ module ApplicationBuilders =
/// <param name="mainPage">The main page widget</param>
static member inline Application(mainPage: WidgetBuilder<'msg, #IFabPage>) =
WidgetHelpers.buildWidgets<'msg, IFabApplication> Application.WidgetKey [| Application.MainPage.WithValue(mainPage.Compile()) |]

static member inline Application<'msg, 'childMarker & #IFabPage>() =
SingleChildBuilder<'msg, IFabApplication, 'childMarker>(
Application.WidgetKey,
Application.MainPage
)

static member inline Application<'msg, 'childMarker>() =
SingleChildBuilder<'msg, IFabApplication, 'childMarker>(Application.WidgetKey, Application.MainPage)

[<Extension>]
type ApplicationModifiers =
Expand Down

0 comments on commit 9a0acf6

Please sign in to comment.