Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
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.