Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposing the entries of a custom map instead of its methods #617

Open
buschtoens opened this issue Sep 30, 2024 · 1 comment
Open

Exposing the entries of a custom map instead of its methods #617

buschtoens opened this issue Sep 30, 2024 · 1 comment

Comments

@buschtoens
Copy link

buschtoens commented Sep 30, 2024

Since 4e76d88 any map type implementing methods will cause those methods to be exposed to JS, but not any of the map entries, to avoid ambiguity.

Now I'm in a scenario where I need the exact opposite behavior: all the map entries should be exposed as properties and none of the methods.

This could be solved with a customizable ToValue: #426

Would you prefer solving this issue via #426 or would you accept a PR with an alternative solution for this case specifically?

For instance, we could use "marker" interfaces:

type ExportEntries interface {
  GojaExportEntries()
}
type Foo map[string]string

// GojaExportEntries is used as a marker for goja to export the map entries instead of its methods.
func (_ Foo) GojaExportEntries() {}

// Without the above, the map would always be exported as an object with this method only.
func (f Foo) SomeMethod() {}
@dop251
Copy link
Owner

dop251 commented Oct 2, 2024

I'd prefer the solution described in #426 as it's more generic and can be allied to 3rd party or built-in types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants