f# - Providing a function that is bound by 3rd party scipt -


i trying write riot tag in fsharp unable without changing riot.

in javascript should provide function like:

function(opts) {   this.on("update",function(opts){     this.opts = opts || this.opts;   }); } 

riot call function using function.prototype.call:

if (impl.fn) { impl.fn.call(this, opts); } 

in f# tried following:

[<emit("this")>] let isthis (x: 'a) : obj = jsnative  let bind fn =   fun o ->     fn (isthis 1) o   [<emit("$0 === undefined")>] let isundefined (x: 'a) : bool = jsnative  bind   (     fun me opts ->       me?on(         "update"         ,(           fun opts ->             if not (isundefined opts)               me?opts <- opts               ()         )       )   ) 

however; bind function transpiled to:

export function bind(fn, o) {   return fn(this)(o); } 

not currying when curry, output looking is:

export function bind(fn) {   return function(o){     return fn(this)(o);   } } 

the way can work change riot.js to:

if (impl.fn) { impl.fn(this)(opts); } 

and provide function in f# in following way:

fun me opts ->   me?on(     "update"     ,(       fun opts ->         if not (isundefined opts)           me?opts <- opts           ()     )   ) 

changing 3rd party libraries satisfy transpiler generated code not ideal. there way transpiler generate output i'm looking for?

[update]

a better way doesn't require changing 3rd party code provide bind function 3rd party javascript:

then import , use bind in template code file:

let jsi =    bind<(obj -> obj -> unit) -> obj>     "../../../js/3rd/jsi.js" bind   (     fun me opts ->       me?on(         "update"         ,(           fun opts ->             if not (isundefined opts)               me?opts <- opts               ()         )       )   ) 


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -