"Simple" form submission? (SourceList vs ObservableCollection) #39
-
I've been trying to get a very basic Elmish loop for my chat window. You know the drill - simple CRUD - just adding to an existing structure and updating the display. I've been looking at the "Action list" and ObservableCollections that are in the Chart ViewModel - and neither seem to be behaving the way I expect. Can you help me get over the hump? Eventually I'll be persisting this to an event store and doing the fully de-coupled CQRS thing - but right now I just want to understand what I'm missing "inside the UI loop". I've been banging my head against this and it seems like I'm missing something "obvious". Thanks again! Recording.2023-12-15.191148.mp4 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
The chat drawer is looking nice! You should just be able to do this: member this.MessagesView = this.BindSourceList(local.Model.Messages) |
Beta Was this translation helpful? Give feedback.
-
ReactiveElmish.Avalonia v1.0.1 is released. This should now properly resolve to member this.Messages = this.BindSourceList(local.Model.Messages) You should also be able to get rid of this line since you already registered the views. |
Beta Was this translation helpful? Give feedback.
-
Just for fun, I replaced your custom View<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel HorizontalAlignment="Stretch">
<StackPanel.Styles>
<Style Selector="Border">
<Setter Property="Margin" Value="10,5,50,5" />
<Setter Property="BorderBrush" Value="Orange" />
<Setter Property="Background" Value="WhiteSmoke" />
</Style>
<Style Selector="Border.isMe">
<Setter Property="Margin" Value="50,5,10,5" />
<Setter Property="BorderBrush" Value="MidnightBlue" />
<Setter Property="Background" Value="White" />
</Style>
</StackPanel.Styles>
<Border CornerRadius="10"
Padding="10"
BorderThickness="2"
Classes.isMe="{Binding IsMe}">
<StackPanel>
<TextBlock FontWeight="Bold" Text="{Binding User}" />
<TextBlock TextWrapping="Wrap" Text="{Binding Text}" />
</StackPanel>
</Border>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate> View Modelmodule Chat =
type Model = { Messages: SourceList<Message> }
and Message = { User: string; Text: string; IsMe: bool }
type Msg =
| SendMessage of string
let init() =
let initialMessages =
[
{ User = "Aiden"; IsMe = false; Text = "Anomaly detected in in-bound data. It mirrors a previous probe attack that has preceded a DDoS cycle by 20 minutes." }
{ User = "Me"; IsMe = true ; Text = "Thanks I see it. Clear the alarm. Is there any news on the wire that this is hitting more than us?" }
]
{ Messages = SourceList.createFrom initialMessages}
let update (msg: Msg) (model: Model) =
match msg with
| SendMessage text ->
{
Messages = model.Messages |> SourceList.add { User = "Me"; IsMe = true; Text = text }
} |
Beta Was this translation helpful? Give feedback.
ReactiveElmish.Avalonia v1.0.1 is released.
This should now properly resolve to
ReadOnlyObservableCollection<Message>
instead ofReadOnlyObservableCollection<obj>
(which causes the Compiled Bindings to fail).You should also be able to get rid of this line since you already registered the views.