Clearing a SourceList? #48
-
@JordanMarr this is an odd question - as it's really a two-parter. So I sending a message from my MainViewModel to my ChatViewModel. I have a button (that resides in MainVM) which dispatches a command to clear the SourceList that populates the chat items in the chat window. member this.ClearChatCommand() =
local.Dispatch ClearChatCommand and the branch in the update function | ClearChatCommand ->
ChatViewModel.DesignVM.ClearChat()
model So far, so good, right? I know! I'm as surprised as anyone. 😸 In the ChatViewModel here's ClearChat() member this.ClearChat() =
local.Dispatch(ClearChat) Which then executes in the update function in the "ClearChat" branch\ | ClearChat ->
printfn "clearing chat history"
model.Messages.Clear()
model and I've also tried | ClearChat ->
printfn "clearing chat history"
{ model with Messages = model.Messages |> SourceList.removeAll } and then - similar to the init() | ClearChat ->
printfn "clearing chat history"
{ model with Messages = SourceList.createFrom [] } and finally in desparation I'm running the init() - which in context here is pretty tame | ClearChat ->
printfn "clearing chat history"
init() |> ignore
model Even better - when I click the button - I see the console echo "clearing chat history" faithfully every time the action is taken. And yet, nothing happens in the chat window. All of the chat messages are still present. :/ Was it something I said, something I didn't say? Is there something about SourceList that I need to know.
Any help/pointers/advice would be appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 11 replies
-
Could it be related to using the Items property? |
Beta Was this translation helpful? Give feedback.
-
Hard to tell what the issue is. Your individual snippets all look fine. |
Beta Was this translation helpful? Give feedback.
-
I just realized that you are calling the | ClearChatCommand ->
ChatViewModel.DesignVM.ClearChat() // <- This is the problem
model
|
Beta Was this translation helpful? Give feedback.
-
There are a bunch of ways you could call the member this.ClearChatCommand() =
let chatView = this.ChatView :> StyledElement
let chatVM = chatView.DataContext :?> ChatViewModel
chatVM.ClearChat() There is no real value to be gained by pushing that into the local Elmish loop, so better to just delete the Another way to do it would be to move your chat messages into the Yet another way would be to use the EventBus pattern that I had in one of the earlier versions of the sample app. |
Beta Was this translation helpful? Give feedback.
There are a bunch of ways you could call the
ClearChat()
method from theMainViewModel
.The easiest way would probably be to just do this:
There is no real value to be gained by pushing that into the local Elmish loop, so better to just delete the
ClearChatCommand
message in yourMainViewModule
and call theChatViewModel
directly from yourMainViewModel
.Another way to do it would be to move your chat messages into the
App
module as global app state. But it's not worth breaking up the modularity you have just to f…