-
I'm obviously doing something stupid. I have an Elmish app defined something like this: type SunshineApp =
{ name: string
// ...
}
type SunshineApps =
{ env: Map<string, string>
apps: SunshineApp list }
type State =
{ sunshineClient: SunshineClient
apps: SunshineApps
selectedApp: string option }
type Msg =
| FetchApps
| FetchAppsSuccess of apps: SunshineApps
| FetchAppsFailure of error: string
| SelectApp of index: int
// init elided
let update (msg: Msg) (state: State) : State * Msg Cmd =
match msg with
| FetchApps ->
state,
Cmd.OfAsync.either
(fun state -> state.sunshineClient.getAppsAsync () |> Async.AwaitTask)
state
FetchAppsSuccess
(fun ex -> ex.Message |> FetchAppsFailure)
| FetchAppsSuccess apps -> { state with apps = apps }, Cmd.none
| FetchAppsFailure error ->
printfn "Failed to fetch apps: %s" error
state, Cmd.none
| SelectApp index ->
{ state with
selectedApp =
if index >= 0 then
Some state.apps.apps[index].name
else
None },
Cmd.none
// view elided
The However, the Listbox that renders The function which renders this part of the UI is defined as: let private createGamesListPanel (state: State) (dispatch) =
DockPanel.create
[ DockPanel.dock Dock.Left
DockPanel.children
[ StackPanel.create
[ StackPanel.margin (Thickness.Parse("0 10 0 0"))
StackPanel.spacing 10.0
StackPanel.dock Dock.Bottom
StackPanel.children
[ mkVerticalStackButton "Refresh Apps" (fun () -> FetchApps |> dispatch)
mkVerticalStackButton "Discover Games" (fun () -> DiscoverGames |> dispatch) ] ]
ListBox.create
[ ListBox.width 300.0
ListBox.viewItems (
state.apps.apps
|> List.map (fun app -> TextBlock.create [ TextBlock.text app.name ])
)
ListBox.selectedItem (state.selectedApp |> Option.defaultValue "")
ListBox.onSelectedIndexChanged (fun index -> SelectApp index |> dispatch) ] ] ]
let view (state: State) (dispatch) =
DockPanel.create
[ DockPanel.margin 10
DockPanel.children
[ createGamesListPanel state dispatch
createZipsPanel state dispatch
ScrollViewer.create
[ ScrollViewer.horizontalScrollBarVisibility ScrollBarVisibility.Auto
ScrollViewer.verticalScrollBarVisibility ScrollBarVisibility.Auto
ScrollViewer.content (createGameDetailsPanel state dispatch) ] ] ] Other changes to I'm obviously doing something stupid... |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
@doxxx I don't see something obvious, but I haven't used elmish in ages. I'm only using our component model. Could you pust a runnable sample? |
Beta Was this translation helpful? Give feedback.
Ahh, now I see what's going on.
You need to add this call to your elmish program. You are only allowed to do UI updates from the UI thread.
Avalonia.FuncUI/src/Avalonia.FuncUI.Elmish/Library.fs
Line 25 in f156f6e