Skip to content

Commit 39a5184

Browse files
committed
Building call instruction
1 parent fbf320f commit 39a5184

File tree

6 files changed

+85
-26
lines changed

6 files changed

+85
-26
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
dop.core.setActionLocal = function(object, action) {
2+
dop.core.setAction = function(object, action) {
33
dop.util.path({a:action}, null, {a:object}, dop.core.setActionMutator);
44
return object;
55
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
dop.core.setActionRemote = function(object, action) {
2+
dop.core.setActionFunction = function(object, action) {
33
dop.util.path({a:action}, null, {a:object}, function(destiny, prop, value, typeofValue, path){
44
if (isFunction(value) && value.name==dop.core.createRemoteFunction.name)
55
dop.set(destiny, prop, value(dop.getObjectDop(object)[0], path.slice(1)));

src/core/protocol/localProcedureCall.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

2-
dop.core.localProcedureCall = function(f, args, resolve, reject, compose) {
2+
dop.core.localProcedureCall = function(f, args, resolve, reject, configureReq, scope) {
33
var req = dop.core.createAsync(), output;
4-
if (isFunction(compose))
5-
req = compose(req);
4+
if (isFunction(configureReq))
5+
req = configureReq(req);
66

77
args.push(req);
88
req.then(resolve).catch(reject);
9-
output = f.apply(req, args);
9+
output = f.apply(scope||req, args);
1010

1111
// Is sync
1212
if (output !== req)

src/protocol/_onsubscribe.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ dop.protocol._onsubscribe = function(node, request_id, request, response) {
1919
if (node.owner[object_owner_id] === undefined) {
2020
collector = dop.collectFirst();
2121
if (dop.isRegistered(request.into))
22-
object = dop.core.setActionRemote(request.into, object_owner);
22+
object = dop.core.setActionFunction(request.into, object_owner);
2323
else
2424
object = dop.register((request.into===undefined) ?
2525
object_owner
2626
:
27-
dop.core.setActionLocal(request.into, object_owner)
27+
dop.core.setAction(request.into, object_owner)
2828
);
2929
dop.core.registerOwner(node, object, object_owner_id);
3030
collector.emitAndDestroy();

src/protocol/call.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ dop.protocol.oncall = function(node, request_id, request) {
2727
object_data = dop.data.object[object_id];
2828

2929
if (isObject(object_data) && isObject(object_data.node[node.token]) && object_data.node[node.token].subscriber) {
30-
var f = dop.util.get(object_data.object, path);
30+
var functionName = path.pop(),
31+
object = dop.util.get(object_data.object, path),
32+
f = object[functionName];
3133
if (isFunction(f)) {
3234
function resolve(value) {
3335
var response = dop.core.createResponse(request_id, 0);
@@ -45,7 +47,7 @@ dop.protocol.oncall = function(node, request_id, request) {
4547
dop.core.localProcedureCall(f, params, resolve, reject, function(req) {
4648
req.node = node;
4749
return req;
48-
});
50+
}, object);
4951
}
5052
}
5153
};

test/transports/call.js

Lines changed: 73 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,83 @@ server.on('connect', function(node) {
1717
serverClient = node;
1818
})
1919

20+
var obj = {
21+
string: function(){
22+
return 'Hello world';
23+
},
24+
undefined: function(){
25+
// returning nothing
26+
},
27+
object: function() {
28+
return {hola:"mundo"}
29+
},
30+
sum: function(a, b) {
31+
return a+b;
32+
},
33+
resolve: function(req) {
34+
req.resolve('resolved');
35+
},
36+
resolveAsync: function(req) {
37+
setTimeout(function() {
38+
req.resolve('resolveAsync');
39+
}, 100);
40+
return req;
41+
},
42+
reject: function(req) {
43+
req.reject('rejected');
44+
},
45+
reject0: function(req) {
46+
req.reject(0);
47+
}
48+
};
2049

2150

22-
test('', function(t) {
23-
var objectServer = {
24-
deep: {
25-
login: function() {
26-
console.log( 'arguments', arguments );
27-
}
28-
}
29-
};
30-
31-
dopServer.onsubscribe(function() {
32-
return objectServer;
33-
})
51+
dopServer.onsubscribe(function() {
52+
return obj;
53+
})
3454

35-
client.subscribe().then(function(obj) {
36-
obj.deep.login('hola', 'mundo');
37-
console.log( obj.deep.login.name );
38-
t.end();
55+
test('TESTING RESOLVE AN REJECTS', function(t) {
56+
57+
client.subscribe().then(function(obj) {
58+
obj.string()
59+
.then(function(value){
60+
t.equal('Hello world', value, 'Returning a string');
61+
return obj.undefined();
62+
})
63+
.then(function(value){
64+
t.equal(undefined, value, 'Returning nothing');
65+
return obj.object();
66+
})
67+
.then(function(value){
68+
t.equal(value.hola, 'mundo', 'Returning an object');
69+
return obj.sum(2, 2);
70+
})
71+
.then(function(value){
72+
t.equal(value, 4, 'Passing two parameters');
73+
return obj.resolve();
74+
})
75+
.then(function(value){
76+
t.equal(value, 'resolved', 'req.resolve instead of return');
77+
return obj.resolveAsync();
3978
})
79+
.then(function(value){
80+
t.equal(value, 'resolveAsync', 'Resolved async');
81+
return obj.reject();
82+
})
83+
.catch(function(value){
84+
t.equal(value, 'rejected', 'req.reject');
85+
return obj.reject0();
86+
})
87+
.then(function(value){
88+
console.log( 'then' );
89+
// return obj.sum(2, 2);
90+
})
91+
.catch(function(value){
92+
console.log( 'catch' );
93+
// return obj.sum(2, 2);
94+
})
95+
})
4096

4197
})
4298

99+

0 commit comments

Comments
 (0)