dbrattli / dbrattli/Fable.Reaction

Stream handling function does not obtain the actual state (it is always the initial one instead)

Open
#212 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
F#
Stars
143
Forks
19
PR merge metrics
No merged PRs in 30d

Description

While building an app via this library stumbled upon a problem that I can't completely understand. Should the stream handling function be designed assuming the input model/state parameter is the actual/current state or the initial one? As I understand [this code](https://github.com/dbrattli/Fable.Reaction/blob/af419d20644d055e71ebfd57783886319890e74c/src/Reaction.fs#L35), it should get the updated state. But in my app the stream's state parameter always retains the initial value.

### Example

[The example](https://github.com/ArtemyB/FableReactionDemo) is simplistic and meaningless -- it is just for demo purpose.

#### Brief explanation

The state contains `SavedInput : string option`, that is taken from HTML Input element after clicking "Save" button.

The messages are `SaveNewInput of string` , `UpperCase` and `LowerCase`. The 1st one is simply propagated from the stream, the last two are ignored if `SavedInput` is `None`:

```fsharp
messages
|> AsyncRx.choose (function
| SaveNewInput _ as msg -> Some msg
| UpperCase
| LowerCase as msg ->
state.SavedInput
|> Option.map (fun _ -> msg)
```

The intent is to ignore the messages `UpperCase` and `LowerCase` until user saves an entered string. So if the stream function obtained the actual state, the example would work properly. However in reality it always ignores `UpperCase` and `LowerCase` messages, because the stream function never gets an updated state -- it always has the initial value.

So this is the problem I want to clarify.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.