You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want the SubModelSeq sample to have more composable code. In particular, I want the counter bindings to be defined with the rest of the counter code and then for those bindings to be "mapped" to higher-level bindings at the App level.
I am trying to achieve this in this branch. Although I am trying to write really good code, I am not suggesting that necessarily merge in any of those commits as is. The primary purpose of this branch is as a proof of concept. I first want to get it working and then consider how to internally structure the code and what the external API should be.
Below, the function Bindings.mapMsgWithModel doesn't exist, but I have almost created it. To get this far, the two important changes are one important change is removing the wrapDispatch feature (which I originally requested, contributed, and later regretted) and changed the type of the binding argument OnCloseRequested from (essentially) 'msg to 'model -> 'msg. I am going to (independently) suggest this second change in a separate issue. (Edited: I did add issue #243 about changing the type of OnCloseRequested, but I realized that it is not important because it doesn't require a change to the public API.)
Tomorrow, I plan to continue trying to create Bindings.mapMsgWithModel. A remaining difficulty is the toMsg binding arguments. I currently don't expect to encounter any other difficulties.
Now to be more specific, I will compare what we have now to what I want. For what we have now, I use the code in PR #241.
Current Code
The counter code is...
typeCounter={ Count:int
StepSize:int }typeCounterMsg=| Increment
| Decrement
| SetStepSize ofint| Reset
moduleCounter =letinit={ Count =0
StepSize =1}letcanReset=(<>) init
letupdate msg m =match msg with| Increment ->{ m with Count = m.Count + m.StepSize }| Decrement ->{ m with Count = m.Count - m.StepSize }| SetStepSize x ->{ m with StepSize = x }| Reset -> init
...which lacks bindings while the recursive bindings are
Instead, I want the counter bindings to be defined with the rest of the Counter code like they are in the SingleCounter sample, which would look like...
typeCounter={ Count:int
StepSize:int }typeCounterMsg=| Increment
| Decrement
| SetStepSize ofint| Reset
moduleCounter =letinit={ Count =0
StepSize =1}letcanReset=(<>) init
letupdate msg m =match msg with| Increment ->{ m with Count = m.Count + m.StepSize }| Decrement ->{ m with Count = m.Count - m.StepSize }| SetStepSize x ->{ m with StepSize = x }| Reset -> init
letbindings():Binding<Counter,CounterMsg>list =["CounterValue"|> Binding.oneWay (fun m -> m.Count)"Increment"|> Binding.cmd Increment
"Decrement"|> Binding.cmd Decrement
"StepSize"|> Binding.twoWay((fun m -> float m.StepSize),
int >> SetStepSize)"Reset"|> Binding.cmdIf(Reset, canReset)]
...and then the recursive bindings would be defined something like this
I want the
SubModelSeq
sample to have more composable code. In particular, I want the counter bindings to be defined with the rest of the counter code and then for those bindings to be "mapped" to higher-level bindings at theApp
level.I am trying to achieve this in this branch. Although I am trying to write really good code, I am not suggesting that necessarily merge in any of those commits as is. The primary purpose of this branch is as a proof of concept. I first want to get it working and then consider how to internally structure the code and what the external API should be.
Below, the function
Bindings.mapMsgWithModel
doesn't exist, but I have almost created it. To get this far,the two important changes areone important change is removing thewrapDispatch
feature (which I originally requested, contributed, and later regretted)and changed the type of the binding argument(Edited: I did add issue #243 about changing the type ofOnCloseRequested
from (essentially)'msg
to'model -> 'msg
. I am going to (independently) suggest this second change in a separate issue.OnCloseRequested
, but I realized that it is not important because it doesn't require a change to the public API.)Tomorrow, I plan to continue trying to create
Bindings.mapMsgWithModel
. A remaining difficulty is thetoMsg
binding arguments. I currently don't expect to encounter any other difficulties.Now to be more specific, I will compare what we have now to what I want. For what we have now, I use the code in PR #241.
Current Code
The counter code is...
...which lacks bindings while the recursive bindings are
Desired Code
Instead, I want the counter bindings to be defined with the rest of the Counter code like they are in the
SingleCounter
sample, which would look like......and then the recursive bindings would be defined something like this
The text was updated successfully, but these errors were encountered: