Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Proposal: allow customizing externalization and internalization logic for user-defined types. #1080

Open
@nevkontakte

Description

@nevkontakte

Note: this is a very rough sketch of a proposal to serve as a reference in other issues, more design work is required to make it fully practical.

Proposal

  • If a user type implements Externalizer interface, GopherJS will use the result of Externalize() method when exporting this object to JavaScript. Otherwise standard conversion rules are applied.
  • If a user type implements Internalizer interface, GopherJS will create a new Go type instance and call Internalize() method on it, passing the original *js.Object in, and will use the instance as internalized value.
package js

type Externalizer interface {
	Externalize() *js.Object
}

type Internalizer interface {
	Internalize(o *js.Object)
}

The general idea is similar to that if Marshaler/Unmarshaler interfaces in package/json.

Motivation

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions