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
My Team has been using the Fun.Blazor library to do a Blazor UI. In the process we've come across two scenarios in which we'd like a ChangeableValue to depend on another IAdaptiveValue.
In the first scenario, We have an incoming ChangeableValue that we want to delay propagating the Mark and Values to until the child has been Committed. We've been calling it DependantChangeableValue<'T> with an implementation like this:
typeDependantChangeableValue<'T>(antecedent: cval<'T>)=inherit AVal.AbstractVal<'T>()// can we avoid double caching (here and in AbstractVal)let mutablecache:ValueOption<'T>= ValueNone
overridex.Compute(token:AdaptiveToken)=match cache with| ValueSome v -> v
|_->
antecedent.GetValue token
memberx.SetValue(v:'T)=
transact(fun _ ->
cache <- ValueSome v
x.MarkOutdated())memberx.UpdateAntecedent()=
transact(fun _ ->match cache with| ValueSome v ->
antecedent.Value <- v
|_->())memberx.WithSetter()=
x |> AVal.map(fun v -> v,x.SetValue)
In the other case we have a UI component that returns a ChangeableValue which represents the result of the components behavior. It's a Changable value because we want other components or systems to be able to change the UI component by changeing this output (think a selected list where the selected item is 'T option and you can clear the selection by setting to None). But I'd also like to have an input IAdaptiveValue and a setter function able to be optionally passed in that would be able to participate in the Changeable value Mark and SetValue. In this way I might be able to route the SetValue through the returned changeable to the setter function.
In both cases we can definitely implement those capabilities with the current Library but they can be used interchangeably with cval. And it turns out that having the ability to represent changeabilty as type would be sort of nice.
So my question I think it might be useful to to have either an IChangeableValue that derives from IAdaptiveValue and provides the hooks so that code that sees cval can work with any particular implementation or unseal ChangeableValue to allow extension for the same reason. I think the IChangeableValue might be the better route but I wanted some feedback about the suggestion.
Another type we also implemented for representing Async computations that might need to be refreshed after you use them (ex. Database queries with the same arguments):
typeAsyncStatus<'T>=| Init
| Ready ofdata:'T| Loading ofmsg:string*elapsed:System.TimeSpan| Error ofmsg:string*when':System.DateTimeOffset[<StructuredFormatDisplay("{AsString}")>]typeAsyncChangeableValue<'T>(async':'TAsync,?loadingMessage:string,?requireRefresh:bool)asthis=inherit AdaptiveObject()// the initial value is AsyncStatus<'T>.Init// thier is also a quiet cache used to attempt refreshing without triggering a change notification until finishedmemberx.Valuewith get
memberx.GetValue(token:AdaptiveToken):AsyncStatus<'T>/// the async version allows the user to await until the operation is completed to continue with another operation./// if a RefreshQuiet was in progress then it is turned into a normal Refresh operation/// if a RefreshAsync in already in flight then this returns an Async<unit> that can be waiting on until the original operation/// complete/// This cause a Refresh to immediately start and the returned Async<unit> is only used to synchronize with the results. Think Async.StartAsChild(...)memberx.RefreshAsync():Async<unit>/// this version triggers a refresh and then immediately returns (fire and forget), internally it fires a RefreshAsync and then ignore the resulting Async<unit>memberx.Refresh():unit/// will cause a refresh of the async computation but will NOT change the state of the cached data/// unless it successfully completes. updateOnlyWhenChanged will execute an expensive comparison on/// the incoming value to only mark this aval as changed if it is not equal to the current value/// ignoreErrors will NOT cause a Change in value if an Error occurs, instead the current value is retained/// if a RefreshAsync was in progress then this returns an Async<unit> that can be waited on until the original operation is complete/// if a RefreshQuietAsync in already in flight then this returns an Async<unit> that can be waiting on until the original operation/// completes/// This cause a Refresh to immediately start and the returned Async<unit> is only used to synchronize with the results. Think Async.StartAsChild(...)memberx.RefreshQuietAsync([<Optional;DefaultParameterValue(false)>]ignoreErrors,[<Optional;DefaultParameterValue(false)>]updateOnlyWhenChanged):Async<unit>/// triggers a RefreshQuietAsync operation and then immediately returns, ignoring the Async<unit> result of RefreshQuiet.memberx.RefreshQuiet([<Optional;DefaultParameterValue(false)>]ignoreErrors)= x.RefreshQuietAsync(ignoreErrors)|> Async.Start
memberresult.MapWithDefault(mapping:'T ->'U,?defaultValue:'U):aval<'U>memberresult.IsErrored:aval<bool>memberresult.IsLoading:aval<bool>memberresult.IsReady:aval<bool>memberresult.ReadyValue:aval<'Toption>memberresult.LoadingMessage:aval<(string * System.TimeSpan)option>memberresult.ErrorMessage:aval<(string * System.DateTimeOffset)option>interface IAdaptiveValue with...interface IAdaptiveValue<DataStatus<'T>> with...memberprivatex.AsString= sprintf "acval(%A)" x.Value
overridex.ToString()= System.String.Format("acval({0})", x.Value)andacval<'T>= AsyncChangeableValue<'T>
Thanks in advance for any comments and suggestions.
-Patrick
I just saw this discussion which did discuss something like the AsyncChangeableValue type above: #101 (comment)
The text was updated successfully, but these errors were encountered:
My Team has been using the Fun.Blazor library to do a Blazor UI. In the process we've come across two scenarios in which we'd like a ChangeableValue to depend on another IAdaptiveValue.
In both cases we can definitely implement those capabilities with the current Library but they can be used interchangeably with cval. And it turns out that having the ability to represent changeabilty as type would be sort of nice.
So my question I think it might be useful to to have either an IChangeableValue that derives from IAdaptiveValue and provides the hooks so that code that sees cval can work with any particular implementation or unseal ChangeableValue to allow extension for the same reason. I think the IChangeableValue might be the better route but I wanted some feedback about the suggestion.
Another type we also implemented for representing Async computations that might need to be refreshed after you use them (ex. Database queries with the same arguments):
Thanks in advance for any comments and suggestions.
-Patrick
I just saw this discussion which did discuss something like the AsyncChangeableValue type above: #101 (comment)
The text was updated successfully, but these errors were encountered: