Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-3122

Javascript struct constructor should properly initialize struct and container members from plain js arguments

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.9.3
    • Component/s: JavaScript - Compiler
    • Labels:
      None
    • Patch Info:
      Patch Available

      Description

      Currently constructors for struct types in generated javascript accept args object and initialize struct's members by simply assigning a value from corresponding args object property (if not undefined). If struct member is
      another struct it must be explicitly created with constructor and passed as an argument value.

      Given following definitions:

      struct A {
             1: string something
      }
      
      struct B {
             1: A value
      }
      

      this works:

      var b1 = new B(
        {
          value: new A(
            {
              something: 'hello'
            }
          )
        }
      );
      

      this doesn't:

      var b2 = new B(
        {
          value: {
            something: 'hello'
          }
        }
      );
      

      Attempt to serialize b2 will result in error because b2.a doesn't have a write method.

      This becomes especially problematic when deep objects are used with libraries like Underscore.js, lodash, React's immutability helpers or Immutable.js: most operations will return or produce plain javascript objects without read/write methods even if Thrift objects were given as input. Manually converting object graphs back to Thrift serializable form is not workable.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              itkach Igor Tkach
            • Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: