From 158c2fe8f3eb359154433df7cd88e36301adc531 Mon Sep 17 00:00:00 2001 From: "Richard T. Carback III" <rick.carback@gmail.com> Date: Wed, 31 May 2023 21:39:33 +0000 Subject: [PATCH] make local events flag optional --- wasm/collective.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/wasm/collective.go b/wasm/collective.go index e2b250a0..cd3dcc38 100644 --- a/wasm/collective.go +++ b/wasm/collective.go @@ -385,6 +385,7 @@ func (r *RemoteKV) GetMapElement(_ js.Value, args []js.Value) any { // - args[0] - the key string // - args[1] - the version int // - args[2] - the [KeyChangedByRemoteCallback] javascript callback +// - args[3] - set the localEvents flag to true or false (optional) // // Returns a promise with an error if any or the json of the existing // [versioned.Object], e.g.: @@ -396,8 +397,13 @@ func (r *RemoteKV) ListenOnRemoteKey(_ js.Value, args []js.Value) any { version := int64(args[1].Int()) cb := newKeyChangedByRemoteCallback(args[2]) + localEvents := true + if !args[3].IsUndefined() { + localEvents = args[3].Bool() + } + promiseFn := func(resolve, reject func(args ...any) js.Value) { - err := r.api.ListenOnRemoteKey(key, version, cb, true) + err := r.api.ListenOnRemoteKey(key, version, cb, localEvents) if err != nil { reject(exception.NewTrace(err)) } else { @@ -415,6 +421,7 @@ func (r *RemoteKV) ListenOnRemoteKey(_ js.Value, args []js.Value) any { // - args[0] - the mapName string // - args[1] - the version int // - args[2] - the [MapChangedByRemoteCallback] javascript callback +// - args[3] - set the localEvents flag to true or false (optional) // // Returns a promise with an error if any or the json of the existing // the [map[string]versioned.Object] JSON value, e.g.: @@ -426,8 +433,13 @@ func (r *RemoteKV) ListenOnRemoteMap(_ js.Value, args []js.Value) any { version := int64(args[1].Int()) cb := newMapChangedByRemoteCallback(args[2]) + localEvents := true + if !args[3].IsUndefined() { + localEvents = args[3].Bool() + } + promiseFn := func(resolve, reject func(args ...any) js.Value) { - err := r.api.ListenOnRemoteMap(mapName, version, cb, true) + err := r.api.ListenOnRemoteMap(mapName, version, cb, localEvents) if err != nil { reject(exception.NewTrace(err)) } else { -- GitLab