Skip to content

Commit

Permalink
Fixed BindOnChanged issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanMarr committed Apr 13, 2024
1 parent 46fe03c commit f4b652a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 19 deletions.
8 changes: 1 addition & 7 deletions src/ReactiveElmish/ReactiveElmishStore.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ type IStore<'Model, 'Msg> =
inherit IStore<'Model>
abstract member Dispatch: 'Msg -> unit

type IHasSubject<'Model> =
abstract member Subject: Subject<'Model> with get

module Design =
/// Stubs a constructor injected dependency in design mode.
let stub<'T> = Unchecked.defaultof<'T>
Expand All @@ -32,10 +29,7 @@ type ReactiveElmishStore<'Model, 'Msg> () =
member this.Dispatch msg = _dispatch msg
member this.Model = _model
member this.Observable = _modelSubject.AsObservable()

interface IHasSubject<'Model> with
member this.Subject = _modelSubject


member this.Dispatcher
with get() = _dispatch
and set(dispatch) = _dispatch <- dispatch
Expand Down
12 changes: 3 additions & 9 deletions src/ReactiveElmish/ReactiveElmishViewModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ type ReactiveElmishViewModel(onPropertyChanged: string -> unit) =
// Creates a subscription to the 'Model projection and stores it in a dictionary.
let disposable =
store.Observable
.DistinctUntilChanged(modelProjection)
.DistinctUntilChanged(modelProjection)
.Subscribe(fun _ ->
// Alerts the view that the 'Model projection / VM property has changed.
onPropertyChanged(vmPropertyName)
#if DEBUG
printfn $"PropertyChanged: {vmPropertyName} by {this}"
printfn $"PropertyChanged: {vmPropertyName}"
#endif
)
propertySubscriptions.Add(vmPropertyName, disposable)
Expand All @@ -75,16 +75,10 @@ type ReactiveElmishViewModel(onPropertyChanged: string -> unit) =
// Alerts the view that the 'Model projection / VM property has changed.
onPropertyChanged(vmPropertyName)
#if DEBUG
printfn $"PropertyChanged: {vmPropertyName} by {this}"
printfn $"PropertyChanged: {vmPropertyName}"
#endif
)

match store with
| :? IHasSubject<'Model> as subject ->
subject.Subject.OnNext(store.Model) // prime the pump
| _ ->
failwith "BindOnChanged requires the store to implement ISubject<'Model>"

propertySubscriptions.Add(vmPropertyName, disposable)

modelProjection store.Model
Expand Down
3 changes: 0 additions & 3 deletions src/ReactiveElmish/ReactiveStore.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ type ReactiveStore<'Model>(init: 'Model) =
_model <- fn _model
_modelSubject.OnNext(_model)

interface IHasSubject<'Model> with
member this.Subject = _modelSubject

interface IDisposable with
member this.Dispose() =
_modelSubject.Dispose()

0 comments on commit f4b652a

Please sign in to comment.