« first day (1448 days earlier)      last day (2076 days later) » 

6:20 PM
time for new question
There are values that change with time.
When the value crosses a certain critical value (each has its own) user have to see MessageBox with information.
Boxes can be opened independent each other.
After the information box is closed, the new one can be displayed no earlier than in some minutes
My first thought was to create record like below:
type NotifyIValue = {
    Value : IMutatable<int>
    State : IMutatable<bool>
    Filter : int -> bool
    WMessage : string
    }
    with
    member x.OnChange =
            x.Value
            |> Observable.filter x.Filter
            |> Observable.filterBy x.State
            |> Observable.map (fun _ -> x)
simple "modeling":
let rec wf () = async {
    printfn "Iteration"
    for d in model do
        d.Value.Value <- rnd.Next 100
        printfn "Set %A to %A" d.WMessage d.Value.Value
        do! Async.Sleep (rnd.Next 10 * 1000)

    do! Async.Sleep 1000
    return! wf()
}
when model is NotifyIValue list
component for displaying:
let nvcontext (nv:NotifyIValue) =
    let source = Bind.createSource()
    nv.Value |> Bind.Explicit.oneWay source "Value"
    nv.State |> Bind.Explicit.oneWay source "State"
    Bind.Explicit.constant "Message" nv.WMessage source
    source

let compB _ source (model:ISignal<NotifyIValue list>) =
    model.Value
    |> List.map nvcontext
    |> Bind.Explicit.constant "Items" <| source

    model.Value
    |> List.map (fun x -> x.OnChange)
transformation:
let transform message _ =
    async {
        message.State.Value <- false
        let msg = message.WMessage
        printfn "%A is processing " msg
        let mb = System.Windows.MessageBox.Show msg
        printfn "%A was closed...wait for 1 minute" msg
        do! Async.Sleep 60000
        printfn "Can show "
        message.State.Value <- true
        return message |> Some
    }
Component.fromExplicit compB
|> Component.withSubscription transform
 
say you want it to show the MB every "10" changes - if one shows, then there are 20 changes over the next 10s, do you want it to show a MB in 1 min, then another in 2 min?
or do you want it to suppress all MB until changes occur after 1m?
 
6:41 PM
first
 
seems like an odd UX :p
I'd model it all in the types, though - not trying to make different mutable combos, etc
just seems simpler
have a record with the value + last notification time, next notification available, etc
and just throw up notifications when appropriate, updating record when you do
 
that's why I asked =) The code above works fine (at least I don't see problem with it) for this simple case, but I have doubt about approach
thanks, I'm going to try make it less mutable
 
tbh, I haven't used a mutable in anything in a long time :p
it's almost always easier to just put the info you want into the model
and not have to think about it
 
7:07 PM
I agree, this case I assessed risks and choose "mutable" road (let me count it not a mistake but experience :-)) After that I have seen that even small changes in task totally break the code. Immutable way seems like more verbose but and more flexible. Perhaps this will be a good way to demonstrate it
 
immutable is just safe/straightforward
with the right data setup, it shouldn't be much more verbose, either
 
I not sure what will be right data setup in this case. Maybe to add property for keeping time of last checking (after when MB is closed)?
 
 
2 hours later…
9:21 PM
@FoggyFinder I typically keep track of the last notification time (ie: last time the MB was closed)
so you don't spam user - easy to filter messages for when that's >1hr
 
9:35 PM
reasonable; grr, why I haven't done it early
 

« first day (1448 days earlier)      last day (2076 days later) »