Running WebSharper code from JavaScript, e.g. making JavaScript your entry-point bypassing WebSharper is possible but is not recommended as you will have to figure out and include the dependencies, which WebSharper does for you automatically.

An obvious way to run a server-side WebSharper function from JavaScript is to wrap it in a client-side function in WebSharper and then call that function.

1
2
3
4
5
6
7
8
9
10
11
12
module My.Module

[<Remote>]
let f a b = async { return a + b }

[<JavaScript>]
let g a b k =
    async {
        let! r = f a b
        return k r
    }

After these declarations you can find the function in JavaScript:

1
My.Module.g(1, 2, function (r) { console.log("RESULT:", r); });
By on 5/15/2012 6:30 AM ()

WebSharper integrates with external JavaScript code using Inline/Direct attributes. For example:

1
2
[<Direct "window.alert($s)">]
let alert (s: string) = ()

For larger APIs there is also Interface Generator. See the documentation:

[link:websharper.com]

By on 5/15/2012 6:26 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