Skip to content

Commit

Permalink
Move preConfiguredProxy into core-client
Browse files Browse the repository at this point in the history
  • Loading branch information
Jashepp committed Feb 13, 2017
1 parent 5855b7f commit 2ecb897
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 33 deletions.
34 changes: 1 addition & 33 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var requireWorkerObj = { exports, __filename, coreClient, coreHost, coreProcessM

coreClient.setRequireWorker(requireWorkerObj);
exports.coreClient = coreClient;
exports.preConfiguredProxy = coreClient.preConfiguredProxy;

coreHost.setRequireWorker(requireWorkerObj);
exports.coreHost = coreHost;
Expand Down Expand Up @@ -53,39 +54,6 @@ requireWorkerObj.getStackFiles = function getStackFiles(){
return result;
};

exports.preConfiguredProxy = (target,options)=>{
var interfaceObj = null, client = null;
var targetIsProxy = false;
if(_.isObject(target) && 'constructor' in target && 'client' in target.constructor && target.constructor.client instanceof coreClient.requireWorkerClient) targetIsProxy = true;
if(!targetIsProxy && _.isObject(target) && 'interfaceObj' in target && 'client' in target){
interfaceObj = target.interfaceObj;
client = target.client;
} else {
var targetIsPromise = !targetIsProxy && _.isPromise(target);
for(var [key,val] of coreClient.clientsMap){
if('proxyCom' in val && 'proxyMap' in val.proxyCom){
if(val.proxyCom.proxyMap.has(target)){
interfaceObj = val.proxyCom.proxyMap.get(target);
client = val;
break;
} else if(targetIsPromise) {
for(var [key2,val2] of val.proxyCom.proxyMap){
if('promiseMap' in val2){
if(val2.promiseMap.has(target)){ interfaceObj = val2; break; }
}
}
if(interfaceObj){
client = val;
break;
}
}
}
}
}
if(!interfaceObj || !client) throw Error("Target not found");
return client.proxyCom.createMainProxyInterface(_.deepExtend(_.deepExtend({},interfaceObj.options),{ preConfigure:options }));
};

const checkNewProcess = ()=>{
if(require.main===module && process.argv.length===4 && process.argv[2]==='--rwProcess'){
var ipcTransportID = process.argv[3];
Expand Down
33 changes: 33 additions & 0 deletions lib/core-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,36 @@ client.prototype = {
return this.proxyCom.createMainProxyInterface({ preConfigure:options });
}
};

exports.preConfiguredProxy = (target,options)=>{
var interfaceObj = null, client = null;
var targetIsProxy = false;
if(_.isObject(target) && 'constructor' in target && 'client' in target.constructor && target.constructor.client instanceof exports.requireWorkerClient) targetIsProxy = true;
if(!targetIsProxy && _.isObject(target) && 'interfaceObj' in target && 'client' in target){
interfaceObj = target.interfaceObj;
client = target.client;
} else {
var targetIsPromise = !targetIsProxy && _.isPromise(target);
for(var [key,val] of clientsMap){
if('proxyCom' in val && 'proxyMap' in val.proxyCom){
if(val.proxyCom.proxyMap.has(target)){
interfaceObj = val.proxyCom.proxyMap.get(target);
client = val;
break;
} else if(targetIsPromise) {
for(var [key2,val2] of val.proxyCom.proxyMap){
if('promiseMap' in val2){
if(val2.promiseMap.has(target)){ interfaceObj = val2; break; }
}
}
if(interfaceObj){
client = val;
break;
}
}
}
}
}
if(!interfaceObj || !client) throw Error("Target not found");
return client.proxyCom.createMainProxyInterface(_.deepExtend(_.deepExtend({},interfaceObj.options),{ preConfigure:options }));
};

0 comments on commit 2ecb897

Please sign in to comment.