Skip to content

Provide a recursive version of js.MakeWrapper() #354

Open
@jakevoytko

Description

@jakevoytko

What strategy do people use to expose nested properties of complex objects? My server has a model with a few levels of nesting, and I would also like it on my client. Using the GopherJS playground, I'm basically in the following situation:

http://www.gopherjs.org/playground/#/ZAk7djDe8v

And I would be happy if either of the following worked in JS:

// Access nested data structures by fields
newA().B.C.DoSomethingCool()

// Access nested data structures using getters
newA().GetB().GetC().DoSomethingCool()

I believe I have the following options:

  • Maintain mirror builders for both the JS and Go versions, so that every NewX() has a NewXWrapper()
  • Use the Reflect package to iterate through my object and build an arbitrarily-complex js.Object
  • Flatten the model so that everything is accessible from A (I don't want to do this, but it may be necessary for mobile anyways)

Is there anything I missed?

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsHelpCommunity contributions are welcome for this feature!enhancement

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions