Skip to content
Snippets Groups Projects
Commit 35ecc599 authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

Implement changes for the multiListener update

parent 0c0ef87a
No related branches found
No related tags found
2 merge requests!132Add Support for Multiple Listeners,!109Project/haven beta
......@@ -48,6 +48,16 @@ func newRemoteKvJS(api *bindings.RemoteKV) map[string]any {
"GetMapElement": js.FuncOf(rkv.GetMapElement),
"ListenOnRemoteKey": js.FuncOf(rkv.ListenOnRemoteKey),
"ListenOnRemoteMap": js.FuncOf(rkv.ListenOnRemoteMap),
"GetAllRemoteKeyListeners": js.FuncOf(
rkv.GetAllRemoteKeyListeners),
"GetRemoteKeyListeners": js.FuncOf(rkv.GetRemoteKeyListeners),
"DeleteRemoteKeyListener": js.FuncOf(
rkv.DeleteRemoteKeyListener),
"GetAllRemoteMapListeners": js.FuncOf(
rkv.GetAllRemoteMapListeners),
"GetRemoteMapListeners": js.FuncOf(rkv.GetRemoteMapListeners),
"DeleteRemoteMapListener": js.FuncOf(
rkv.DeleteRemoteMapListener),
}
return rkvMap
......@@ -403,11 +413,12 @@ func (r *RemoteKV) ListenOnRemoteKey(_ js.Value, args []js.Value) any {
}
promiseFn := func(resolve, reject func(args ...any) js.Value) {
err := r.api.ListenOnRemoteKey(key, version, cb, localEvents)
id, err := r.api.ListenOnRemoteKey(key, version, cb,
localEvents)
if err != nil {
reject(exception.NewTrace(err))
} else {
resolve()
resolve(id)
}
}
......@@ -439,17 +450,92 @@ func (r *RemoteKV) ListenOnRemoteMap(_ js.Value, args []js.Value) any {
}
promiseFn := func(resolve, reject func(args ...any) js.Value) {
err := r.api.ListenOnRemoteMap(mapName, version, cb, localEvents)
id, err := r.api.ListenOnRemoteMap(mapName, version, cb,
localEvents)
if err != nil {
reject(exception.NewTrace(err))
} else {
resolve()
resolve(id)
}
}
return utils.CreatePromise(promiseFn)
}
// GetAllRemoteKeyListeners returns a JSON list of { key: [id, id, id, ...] },
// where key is the key for the listener and the list is an list of integer ids
// of each listener.
func (r *RemoteKV) GetAllRemoteKeyListeners() any {
return r.api.GetAllRemoteKeyListeners()
}
// GeRemoteKeyListeners returns a JSON list of [id, id, id, ...],
// where the list is an list of integer ids of each listener.
//
// Parameters:
// - args[0] - the key to look at
func (r *RemoteKV) GetRemoteKeyListeners(_ js.Value, args []js.Value) any {
key := args[0].String()
return r.api.GetRemoteKeyListeners(key)
}
// DeleteRemoteKeyListener deletes a specific listener for a key.
//
// Parameters:
// - args[0] - the key to delete for
// - args[1] - the id of the listener
func (r *RemoteKV) DeleteRemoteKeyListener(_ js.Value, args []js.Value) any {
key := args[0].String()
id := args[1].Int()
promiseFn := func(resolve, reject func(args ...any) js.Value) {
err := r.api.DeleteRemoteKeyListener(key, id)
if err != nil {
reject(execption.NewTrace(err))
} else {
resolve()
}
}
return utils.CreatePromiseFn(promisFn)
}
// GetAllRemoteMapListeners returns a JSON list of { key: [id, id, id, ...] },
// where key is the key for the listener and the list is an list of integer ids
// of each listener.
func (r *RemoteKV) GetAllRemoteMapListeners() any {
return r.api.GetAllRemoteMapListeners()
}
// GeRemoteMapListeners returns a JSON list of [id, id, id, ...],
// where the list is an list of integer ids of each listener.
//
// Parameters:
// - args[0] - the key to look at
func (r *RemoteKV) GetRemoteMapListeners(_ js.Value, args []js.Value) any {
key := args[0].String()
return r.api.GetRemoteMapListeners(key)
}
// DeleteRemoteMapListener deletes a specific listener for a key.
//
// Parameters:
// - args[0] - the mapName to delete for
// - args[1] - the id of the listener
func (r *RemoteKV) DeleteRemoteMapListener(_ js.Value, args []js.Value) any {
mapName := args[0].String()
id := args[1].Int()
promiseFn := func(resolve, reject func(args ...any) js.Value) {
err := r.api.DeleteRemoteMapListener(mapName, id)
if err != nil {
reject(execption.NewTrace(err))
} else {
resolve()
}
}
return utils.CreatePromiseFn(promisFn)
}
////////////////////////////////////////////////////////////////////////////////
// RemoteStore //
////////////////////////////////////////////////////////////////////////////////
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment