I'm new to Elmish.Xamarin and Xamarin itself. I'm trying to build an application, using this calculator example. Main difference is that in this example UI is updated upon user input, and update
function is pure and just evaluates next state of model:
let update msg model =
match msg with
| Clear -> Initial
| Digit digit ->
match model with
| Initial | Error | Result _ -> Operand (double digit)
| Operand op -> Operand (double (string op + string digit))
| OperandOperator (operand, operator) -> OperandOperatorOperand (operand, operator, double digit)
| OperandOperatorOperand (op1, operator, op2) -> OperandOperatorOperand (op1, operator, double (string op2 + string digit))
| Operator operator ->
match model with
| Initial | Error -> model
| Result operand // previously calculated result is now the first operand
| Operand operand | OperandOperator (operand, _) -> OperandOperator(operand, operator)
| OperandOperatorOperand _ -> calculate model msg
| Equals -> calculate model msg
I need a different scenario: user's input doesn't affect UI directly, instead I store user's messages and evaluate next state on schedule, so in my app's core I pass updateUI: gameState -> unit
func:
let gameAgentFn (mailboxNetwork: MailboxNetwork) updateUi gameState cmd =
let timerAgent = timerAgent mailboxNetwork
match gameState.gameFrame with
| Frame field ->
let gameState = Game.updateGameState gameState cmd
timerAgent.Post Next
updateUi gameState
gameState
Problem is I can't understand, what function to pass and how to build interaction with this design, since as far as I can see, it expects me to pass pure function to evaluate next state and the rest is being done underneath.