You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2015/05/01 20:49:09 UTC

[jira] [Commented] (THRIFT-3122) Javascript struct constructor should properly initialize struct and container members from plain js arguments

    [ https://issues.apache.org/jira/browse/THRIFT-3122?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14523655#comment-14523655 ] 

ASF GitHub Bot commented on THRIFT-3122:
----------------------------------------

GitHub user itkach opened a pull request:

    https://github.com/apache/thrift/pull/476

    THRIFT-3122 Convert plain js objects given as thrift struct constructor arguments to thrift structs

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/itkach/thrift THRIFT-3122

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/thrift/pull/476.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #476
    
----
commit 29b28079ef4c72c74cb6d3234ae3abd2d38168dd
Author: Igor Tkach <it...@aarddict.org>
Date:   2015-04-29T02:50:10Z

    Construct struct instances from arguments

commit 5644aeaa4ba92d93d48014b838d7f8eaa89d52a8
Author: Igor Tkach <it...@aarddict.org>
Date:   2015-04-29T03:32:07Z

    When initializing struct from arguments create new struct instances for list and sets of structs

commit 831712e586b935ea54f2b3b73e451e5a25a7fd7d
Author: Igor Tkach <it...@aarddict.org>
Date:   2015-04-29T21:30:05Z

    Construct struct from map values

commit cd8b5379d014ab218e2e1b48a2b37fad1571c3eb
Author: Igor Tkach <it...@aarddict.org>
Date:   2015-04-30T00:41:04Z

    Rename js copy functions to make it clearer what they are when polluting global in non-commonJS environment

commit 3929979f8e4fa5cc263c814dd44cc6fd724b09bb
Author: Igor Tkach <it...@aarddict.org>
Date:   2015-05-01T17:10:13Z

    Implement copying structs inside deeply nested containers

----


> Javascript struct constructor should properly initialize struct and container members from plain js arguments
> -------------------------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-3122
>                 URL: https://issues.apache.org/jira/browse/THRIFT-3122
>             Project: Thrift
>          Issue Type: Improvement
>          Components: JavaScript - Compiler
>    Affects Versions: 1.0
>            Reporter: Igor Tkach
>
> 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:
> {code}
> struct A {
>        1: string something
> }
> struct B {
>        1: A value
> }
> {code}
> this works:
> {code:javascript}
> var b1 = new B(
>   {
>     value: new A(
>       {
>         something: 'hello'
>       }
>     )
>   }
> );
> {code}
> this doesn't:
> {code:javascript}
> var b2 = new B(
>   {
>     value: {
>       something: 'hello'
>     }
>   }
> );
> {code}
> 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|http://underscorejs.org/], [lodash|https://lodash.com/], [React's immutability helpers|https://facebook.github.io/react/docs/update.html] or [Immutable.js|https://github.com/facebook/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.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)