From b229763dad27bb55cae9219f07962b9870874f19 Mon Sep 17 00:00:00 2001 From: Jono Wenger <jono@elixxir.io> Date: Tue, 21 Mar 2023 10:33:05 -0700 Subject: [PATCH] Add constructors for eventModelBuilder and dmReceiverBuilder to avoid the GoLand linter bug --- wasm/channels.go | 11 ++++++++--- wasm/dm.go | 9 +++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/wasm/channels.go b/wasm/channels.go index 0746c596..a775928e 100644 --- a/wasm/channels.go +++ b/wasm/channels.go @@ -265,8 +265,7 @@ func GetPublicChannelIdentityFromPrivate(_ js.Value, args []js.Value) any { // - Throws a TypeError if creating the manager fails. func NewChannelsManager(_ js.Value, args []js.Value) any { privateIdentity := utils.CopyBytesToGo(args[1]) - - em := &eventModelBuilder{args[2].Invoke} + em := newEventModelBuilder(args[2]) cm, err := bindings.NewChannelsManager(args[0].Int(), privateIdentity, em) if err != nil { @@ -298,7 +297,7 @@ func NewChannelsManager(_ js.Value, args []js.Value) any { // - Javascript representation of the [ChannelsManager] object. // - Throws a TypeError if loading the manager fails. func LoadChannelsManager(_ js.Value, args []js.Value) any { - em := &eventModelBuilder{args[2].Invoke} + em := newEventModelBuilder(args[2]) cm, err := bindings.LoadChannelsManager(args[0].Int(), args[1].String(), em) if err != nil { utils.Throw(utils.TypeError, err) @@ -1753,6 +1752,12 @@ type eventModelBuilder struct { build func(args ...any) js.Value } +// newEventModelBuilder maps the methods on the Javascript object to a new +// eventModelBuilder. +func newEventModelBuilder(arg js.Value) *eventModelBuilder { + return &eventModelBuilder{build: arg.Invoke} +} + // Build initializes and returns the event model. It wraps a Javascript object // that has all the methods in [bindings.EventModel] to make it adhere to the Go // interface [bindings.EventModel]. diff --git a/wasm/dm.go b/wasm/dm.go index f5d43816..e3f71e28 100644 --- a/wasm/dm.go +++ b/wasm/dm.go @@ -85,8 +85,7 @@ func newDMClientJS(api *bindings.DMClient) map[string]any { // - Throws a TypeError if creating the manager fails. func NewDMClient(_ js.Value, args []js.Value) any { privateIdentity := utils.CopyBytesToGo(args[1]) - - em := &dmReceiverBuilder{args[2].Invoke} + em := newDMReceiverBuilder(args[2]) cm, err := bindings.NewDMClient(args[0].Int(), privateIdentity, em) if err != nil { @@ -570,6 +569,12 @@ type dmReceiverBuilder struct { build func(args ...any) js.Value } +// newDMReceiverBuilder maps the methods on the Javascript object to a new +// dmReceiverBuilder. +func newDMReceiverBuilder(arg js.Value) *dmReceiverBuilder { + return &dmReceiverBuilder{build: arg.Invoke} +} + // Build initializes and returns the event model. It wraps a Javascript object // that has all the methods in [bindings.EventModel] to make it adhere to the Go // interface [bindings.EventModel]. -- GitLab