Skip to content

Commit

Permalink
feat: OnAsyncCallback should handle more than two parameters
Browse files Browse the repository at this point in the history
closes #309
  • Loading branch information
SML-MeSo committed Jun 19, 2020
1 parent 7d2b102 commit a262d10
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/internal/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,29 +128,30 @@ export function finalCallback(message) {
}

let asyncCallback = window.OnAsyncCallback;
window.OnAsyncCallback = function(asyncID: number, result: string) {
window.OnAsyncCallback = function(asyncID: number, ...result) {
let formattedResult;
try {
formattedResult = result.map(res => decodeURIComponent(res));
} catch(e) {
formattedResult = result;
}

// Used by proxy to return Async calls
if (Remote.remoteType === 'proxy') {
let callback = _proxyCallbacks[asyncID];
if (callback instanceof Function) {
callback(decodeURIComponent(result));
callback(...formattedResult);
delete _proxyCallbacks[asyncID];
}
} else {
let callback = _callbacks[asyncID];

if (callback instanceof Function) {
try {
callback(decodeURIComponent(result));
delete _callbacks[asyncID];
} catch(e) {
callback(result);
delete _callbacks[asyncID];
}
callback(...formattedResult);
delete _callbacks[asyncID];
}
}

if(typeof asyncCallback === 'function') {
asyncCallback(asyncID, result);
asyncCallback(asyncID, ...result);
}
}

0 comments on commit a262d10

Please sign in to comment.