Announcement

Collapse
No announcement yet.

Problem with Script.Get

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • AndersMalmgren
    started a topic Problem with Script.Get

    Problem with Script.Get

    Hi, Im looking into Bridge.NET

    I try to bridge a third party JS library.

    Here is my test code

        public static class Ko
        {
    
            public delegate T ObservableDelegate<T>(T value = default(T));
    
            public static ObservableDelegate<T> Observable<T>(T value)
            {
                var observable = Script.Get<Func<T, ObservableDelegate<T>>>("ko.observable");
                return observable(value);
            }
        }
    
        public class App
        {
    
            public static void Main()
            {
                var observable = Ko.Observable("value");
                Console.WriteLine(observable());
            }
        }
    This gives expcetion

    Uncaught TypeError: Converting circular structure to JSON
    at JSON.stringify (<anonymous>)
    at Function.logBase (bridge.console.js:95)
    at Function.log (bridge.console.js:129)
    at Function.System.Console.WriteLine (bridge.console.js:47)
    at Function.Main (App.cs:33)
    at bridge.js:3321
    at HTMLDocument.delayfn (bridge.js:595)
    at HTMLDocument.listenHandler (bridge.js:615)

    What am I doing wrong?
    Last edited by AndersMalmgren; 2019-03-10 @ 03:29 PM.

  • fabricio.murta
    replied
    Hello AndersMalmgren, and welcome to Bridge forums!

    To make Bridge call it without parameters you should just remove the {0} bit from the template. It would probably help reading the wiki entry we have for the template attribute: https://github.com/bridgedotnet/Brid...rence#template.

    Hope this helps!

    Leave a comment:


  • samuelgrahame
    replied
    you could use below: it will be like you wrote the javascript.

    /*@
    insert javascript here.            
    */

    Leave a comment:


  • AndersMalmgren
    replied
    This could have worked,
            [ExpandParams]
            public delegate T ObservableDelegate<T>(params T[] value);
    But expand params does nto seem to do what teh docs suggset, since the rsulting javascript is

    this.Foo(["foo"]);
    Which is not what I am after

    Leave a comment:


  • AndersMalmgren
    replied
    I lied. IT does not work.

    this.Foo() which should just return the value of the observables instead does

    this.Foo(void 0)
    Which breaks. Can I tell Bridge to just call it without parameters somehow?

    Leave a comment:


  • AndersMalmgren
    replied
    This works!

        public static class Ko
        {
            public delegate T ObservableDelegate<T>(T value = (dynamic)null);
    
            [Template("ko.applyBindings({0})")]
            public extern static void ApplyBindings<TMOdel>(TMOdel model);
    
            [Template("ko.observable({0})")]
            public extern static ObservableDelegate<T> Observable<T>(T value = default(T));
        }

    Leave a comment:

Working...
X