fix bug in subscribe with param
This commit is contained in:
+8
-3
@@ -96,6 +96,7 @@ export class RPCSocket implements I.Socket{
|
||||
const info:T.ExtendedRpcInfo[] = await this.info()
|
||||
info.forEach(i => {
|
||||
let f: any
|
||||
|
||||
switch (i.type) {
|
||||
case 'Call':
|
||||
f = this.callGenerator(i.uniqueName, i.argNames, sesame)
|
||||
@@ -138,14 +139,18 @@ export class RPCSocket implements I.Socket{
|
||||
* @param fnArgs A string-list of parameters
|
||||
*/
|
||||
private frontEndHookGenerator(fnName: string, fnArgs:string[], sesame?:string): T.HookFunction{
|
||||
fnArgs.pop()
|
||||
|
||||
if(sesame)
|
||||
fnArgs.shift()
|
||||
|
||||
let headerArgs = fnArgs.join(",")
|
||||
const argParams = fnArgs.map(stripAfterEquals).join(",")
|
||||
sesame = appendComma(sesame)
|
||||
headerArgs = appendComma(headerArgs)
|
||||
sesame = appendComma(sesame, true)
|
||||
headerArgs = fnArgs.length>0?headerArgs+",":headerArgs
|
||||
|
||||
return eval( `
|
||||
async (${headerArgs} callback) => {
|
||||
|
||||
const r = await this.socket.call("${fnName}", ${sesame} ${argParams})
|
||||
if(r && r.result === 'Success'){
|
||||
this.socket.hook(r.uuid, callback)
|
||||
|
||||
+7
-4
@@ -115,7 +115,7 @@ const hookGenerator = (rpc:T.HookRPC<any, any, any>, errorHandler: T.ErrorHandle
|
||||
const args = sesameFn?(['sesame', ...argsArr].join(','))
|
||||
:callArgs
|
||||
|
||||
callArgs = appendComma(callArgs)
|
||||
callArgs = appendComma(callArgs, false)
|
||||
|
||||
//note rpc.hook is the associated RPC, not a socket.hook
|
||||
return eval(`
|
||||
@@ -143,7 +143,8 @@ const makeError = (callName: string) => {
|
||||
*/
|
||||
const extractArgs = (f:Function):string[] => {
|
||||
let fn:string
|
||||
return (fn = String(f)).substr(0, fn.indexOf(")")).substr(fn.indexOf("(")+1).split(",")
|
||||
fn = (fn = String(f)).substr(0, fn.indexOf(")")).substr(fn.indexOf("(")+1)
|
||||
return fn!==""?fn.split(',') : []
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,8 +171,10 @@ export function makeSesameFunction (sesame : T.SesameFunction | string) : T.Sesa
|
||||
}
|
||||
|
||||
|
||||
export function appendComma(s?:string):string{
|
||||
return s?`'${s}',`:""
|
||||
export function appendComma(s?:string, turnToString = true):string{
|
||||
if(turnToString)
|
||||
return s?`'${s}',`:""
|
||||
return s?`${s},`:""
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user