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

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 0.9.3
    • JavaScript - Compiler
    • None
    • 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

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

            Dates

              Created:
              Updated:
              Resolved: