Announcement

Collapse
No announcement yet.

[CLOSED] [#2276] [16.0.0] [15.6.0] ObjectCreateMode.Plain is ignored in ObjectLiteral attribute

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

    [CLOSED] [#2276] [16.0.0] [15.6.0] ObjectCreateMode.Plain is ignored in ObjectLiteral attribute

    Before 15.6.0 I used a lot of [ObjectLiteral] throughout my code. After upgrading to 15.6.0 I found that Bridge now calls a constructor on those objects, which seems to destroy the whole purpose of ObjectLiteral in my opinion.

    Anyway, I found out that I could use ObjectCreateMode.Plain to go back to the old behavior, but Bridge seems to ignore that:

    C# class:
    [ObjectLiteral(ObjectCreateMode.Plain)]
    public class HistoryEntry
    {
        public Guid ViewControllerId { get; set; }
    
        public string Hash { get; set; }
    }
    generated JS to create such an object:
    var he = BootForms.Bridge.Utils.HistoryEntry.ctor({ });
    When really it should be:
    var he = { };
    As soon as a class becomes a "real" JS object this poses a big problem when JS wants to clone the object for serialization, such as saving it to the browser history stack.

    I temporarily solved the problem by decorating my class with [External], but I really would like to get the old behavior back. Thanks!

    Marco
    Last edited by geoffrey.mcgill; 2017-01-17 @ 04:39 AM.

    #2
    Hi

    That ctor is used without new keyword (just like initialization function) and returns plain object therefore the behaviour is the same still
    http://deck.net/e46cd0e51b09475cc499ab437c382614
    Last edited by geoffrey.mcgill; 2017-01-15 @ 02:19 AM.

    Comment


      #3
      Hi Marco,

      The changes described in Pull Request (in part of the fix for #2106) require to have type information even for literals.

      As Vladimir mentioned, 15.6's var h = Demo.HistoryEntry.ctor({ }); is still returns a real plain object.

      You are absolutely right - if you need var h = { }; output then you use [External] (Deck):
      [External]
      [ObjectLiteral]
      public class HistoryEntry
      {
          public Guid ViewControllerId { get; set; }
          public string Hash { get; set; }
      }
      
      public class Program
      {
          public static void Main()
          {
              var h = new HistoryEntry();
              var h1 = new HistoryEntry()
              {
                  Hash = "1"
              };
          }
      }
      That will generate
      var h = {  };
      var h1 = { hash: "1" };

      Comment


        #4
        Thanks a lot guys! Bridge.NET rocks!

        Comment


          #5
          We're making some refinements to the [ObjectLiteral] attribute in Bridge 16.0.0.

          Issue #2276 is being used to track progress of these revisions.

          Basically, as of Bridge 16.0.0, applying the [ObjectLiteral] attribute to a class will instruct the compiler to emit a plain { key: value } JavaScript object.

          The recommended action from this thread of adding the [External] attribute would not be required as of Bridge 16.0.0.

          If Type information is required in the Object Literal, please include the ObjectCreateMode.Constructor property on the attribute.

          Example

          [ObjectLiteral(ObjectCreateMode.Constructor)]
          public class Person { }
          This thread will be updated once these refinements have be committed to the master branch, before the official 16.0.0 release.

          Hope this helps
          Last edited by geoffrey.mcgill; 2017-02-07 @ 08:10 PM.

          Comment


            #6
            Hi guys, thanks a lot for your help! I will use Deck in the future :-)

            Comment


              #7
              We're getting closer to accepting the ObjectLiteral revisions into the master branch. These updates will be included in Bridge 16.0.0.
              Last edited by geoffrey.mcgill; 2017-02-07 @ 08:11 PM.

              Comment


                #8
                Fix for issue #2276 merged into master branch (Pull Request #2283) and will be included into the Bridge 16.0.0 release.
                Last edited by geoffrey.mcgill; 2017-02-07 @ 08:11 PM.

                Comment

                Working...
                X