Skip to content

Commit 4fc3e3d

Browse files
committed
Implementing call instruction
1 parent 9f45c74 commit 4fc3e3d

File tree

13 files changed

+100
-37
lines changed

13 files changed

+100
-37
lines changed

src/api/decode.js

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

2-
dop.decode = function(data) {
3-
var undefineds = [],
2+
dop.decode = function(data, node) {
3+
var functions = [],
4+
undefineds = [],
45
index = 0,
56
total,
67
output = JSON.parse(data, function(property, value) {
7-
return dop.core.decode.call(this, property, value, undefineds);
8+
return dop.core.decode.call(this, property, value, functions, undefineds);
89
});
910

10-
for (total=undefineds.length; index<total; ++index)
11+
12+
for (total=functions.length; index<total; ++index)
13+
functions[index][0][functions[index][1]] = dop.core.createRemoteFunction(node);
14+
15+
for (total=undefineds.length,index=0; index<total; ++index)
1116
undefineds[index][0][undefineds[index][1]] = undefined;
1217

1318
return output;

src/api/setAction.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
dop.setAction = function(actions) {
33
var collector = dop.collectFirst(), object_id;
44
for (object_id in actions)
5-
dop.core.setAction(actions[object_id].object, actions[object_id].action);
5+
dop.core.setActionLocal(actions[object_id].object, actions[object_id].action);
66
return collector;
77
};

src/core/api_transports/emitMessage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dop.core.emitMessage = function(node, message_string, message_raw) {
1111

1212
// Parsing messages
1313
if (typeof message_string == 'string' && message_string.substr(0,1) == '[') {
14-
try { messages = dop.decode(message_string); }
14+
try { messages = dop.decode(message_string, node); }
1515
catch(e) { /*console.log(e);*/ }
1616
}
1717
else

src/core/objects/configureObject.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ dop.core.configureObject = function(object, path, parent) {
1717
var property, value, object_dop;
1818
for (property in object) {
1919
value = object[property];
20-
if (dop.isObjectRegistrable(value))
20+
if (isFunction(value) && value.name==dop.core.createRemoteFunction.name)
21+
object[property] = value(path[0], path.slice(1).concat(property));
22+
else if (dop.isObjectRegistrable(value))
2123
object[property] = dop.core.configureObject(value, path.concat(property), object);
2224
}
2325

src/core/objects/setActionLocal.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
dop.core.setActionLocal = function(object, action) {
3+
dop.util.path({a:action}, null, {a:object}, dop.core.setActionMutator);
4+
return object;
5+
};
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11

2-
dop.core.setAction = function(object, action) {
3-
dop.util.path({a:action}, null, {a:object}, dop.core.setActionMutator);
4-
return object;
5-
};
6-
72
dop.core.setActionMutator = function(destiny, prop, value, typeofValue, path) {
83

94
// if (path.length > 1) {
@@ -36,7 +31,7 @@ dop.core.setActionMutator = function(destiny, prop, value, typeofValue, path) {
3631
// set
3732
if (mutation.length===3 && mutation[1]===1) {
3833
(mutation[2] === undefined) ?
39-
dop.del(destiny[prop], mutation[0])
34+
dop.del(destiny[prop], mutation[0])
4035
:
4136
dop.set(destiny[prop], mutation[0], mutation[2]);
4237
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
dop.core.setActionRemote = function(object, action) {
3+
dop.util.path({a:action}, null, {a:object}, function(destiny, prop, value, typeofValue, path){
4+
return (isFunction(value) && value.name==dop.core.createRemoteFunction.name) ?
5+
dop.set(destiny, prop, value(dop.getObjectDop(object)[0], path.slice(1)))
6+
:
7+
dop.core.setActionMutator(destiny, prop, value, typeofValue, path);
8+
});
9+
return object;
10+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
dop.core.createRemoteFunction = function $DOP_REMOTE_FUNCTION_UNSETUP(node) {
3+
return function $DOP_REMOTE_FUNCTION_UNSETUP(object_id, path) {
4+
// // http://jsperf.com/dynamic-name-of-functions
5+
// return new Function(
6+
// "var a=arguments;return function " + path[path.length-1] + "(){return a[0](a[1], a[2], a[3], arguments)}"
7+
// )(dop.protocol.call, node, object_id, path)
8+
return function $DOP_REMOTE_FUNCTION() {
9+
return dop.protocol.call(node, object_id, path, arguments);
10+
}
11+
}
12+
};
13+
dop.protocol.call = function(node, object_id, path, params) {
14+
15+
var params = Array.prototype.slice.call(params, 0);
16+
17+
console.log(node.token, dop.data.object[object_id].node[node.token].owner, path, params);
18+
};

src/core/protocol/decode.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
var regexpdate = /^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d.\d\d\dZ$/,
22
regexpsplit = /\/(.+)\/([gimuy]{0,5})/;
33

4-
dop.core.decode = function(property, value, undefineds) {
4+
dop.core.decode = function(property, value, functions, undefineds) {
55

66
if (typeof value == 'string') {
77

8-
if (value === '~F')
9-
return dop.core.remoteFunction(this, property);
8+
if (value === '~F') {
9+
functions.push([this, property]);
10+
return undefined;
11+
}
1012

1113
if (value == '~U' && isObject(undefineds)) {
1214
undefineds.push([this, property]); // http://stackoverflow.com/questions/17648150/how-does-json-parse-manage-undefined

src/core/protocol/remoteFunction.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)