(Summarizing the problem and the solution here for the record)

When passing a top-level function to a call that expects a lambda, WebSharper 3 (not 4) wraps it in a lambda, so it's a different actual function every time and that messes with things like unsubscribing from events which expects the exact same function object. The solution is to create a local lambda by hand:

1
2
3
4
5
6
7
8
9
10
11
12
// Top-level function
let subscribeFn (data:obj) = JS.Alert(data :?> string)

let test() =
    // This doesn't work because the two instances of `subscribeFn` are different lambdas:
    Amplify.Amplify.Subscribe("tryPubSub", subscribeFn)
    Amplify.Amplify.Unsubscribe("tryPubSub", subscribeFn)

    // This works:
    let subscribeFn = fun (o: obj) -> subscribeFn o
    Amplify.Amplify.Subscribe("tryPubSub", subscribeFn)
    Amplify.Amplify.Unsubscribe("tryPubSub", subscribeFn)
By on 8/30/2016 6:50 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper