For one, you could use FuncWithArgs and friends. Problem is WebSharper can't figure out what calling convention to use when you only pass a fun so you have to spell it out explicitly. Example:

1
2
3
[<Inline "$f($a, $b)">]
let CallWithTwoParams' (a: 'T) (b: 'U) (f: FuncWithArgs<'T * 'U, unit>) = ()
let CallWithTwoParams a b f = CallWithTwoParams' a b <| FuncWithArgs(f)

then you could use this like so:

1
2
CallWithTwoParams 2 "foo" (fun (x, y) -> 
	Console.Log(x); Console.Log(y))
By on 1/29/2016 1:50 AM ()

Nice! Thanks, FuncWithArgs is what I needed!

By on 1/29/2016 5:19 AM ()

I figured I could place the arguments in an array and cast it in the callback like so:

1
2
3
4
5
6
7
8
[<Direct """jQuery.each($arr, function(i, val) { $exec([ i, val ]); })""">]
let each (arr: string []) (exec: obj [] -> unit) = X<unit>

let Main =
    each [| "a"; "b" |] (fun args -> 
        let i = args.[0] :?> int
        let s = args.[1] :?> string
        JS.Alert (string i + " " + s))

But this doesn't look good, is there another way?

By on 1/28/2016 2:59 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