Skip to content

Commit dce8212

Browse files
committed
Broadcast instruction implemented
1 parent dcf6cde commit dce8212

File tree

18 files changed

+651
-329
lines changed

18 files changed

+651
-329
lines changed

dist/browser.js

Lines changed: 234 additions & 134 deletions
Large diffs are not rendered by default.

dist/browser.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/nodejs.js

Lines changed: 234 additions & 134 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dop",
3-
"version": "0.8.0",
3+
"version": "0.9.0",
44
"main": "./dist/nodejs.js",
55
"browser": "./dist/browser.js",
66
"unpkg": "./dist/browser.min.js",

src/api/isBroadcastFunction.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
dop.isBroadcastFunction = function(fun) {
3+
return (isFunction(fun) && fun.name===dop.cons.BROADCAST_FUNCTION);
4+
};

src/api/setBroadcastFunction.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
dop.setBroadcastFunction = function (object, namefunction) {
3+
dop.util.invariant(dop.isRegistered(object), 'Object passed to dop.setBroadcastFunction must be a registered object');
4+
var path = dop.getObjectDop(object).slice(0),
5+
object_id = path.shift();
6+
path.push(namefunction);
7+
dop.getObjectTarget(object)[namefunction] = function $DOP_BROADCAST_FUNCTION() {
8+
return dop.protocol.broadcast(object_id, path, arguments);
9+
}
10+
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

22
dop.core.encodeFunction = function(property, value) {
3-
return (isFunction(value)) ? '~F' : dop.core.encode(property, value);
3+
return (isFunction(value) && !dop.isBroadcastFunction(value)) ? '~F' : dop.core.encode(property, value);
44
};

src/dop.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var dop = {
2828
SEND: '~SEND',
2929
DISCONNECT: '~DISCONNECT',
3030
REMOTE_FUNCTION: '$DOP_REMOTE_FUNCTION',
31+
BROADCAST_FUNCTION: '$DOP_BROADCAST_FUNCTION',
3132
}
32-
33+
3334
};

src/protocol/_onbroadcast.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
dop.protocol._onbroadcast = function(node, request_id, request, response) {
3+
dop.protocol._oncall(node, request_id, request, response);
4+
};

src/protocol/_oncall.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
dop.protocol._oncall = function(node, request_id, request, response) {
3+
var rejection = response[0],
4+
promise = request.promise;
5+
if (rejection !== undefined) {
6+
if (rejection === 0)
7+
promise.resolve(response[1]);
8+
else if (rejection===dop.core.error.reject_remote.CUSTOM_REJECTION)
9+
promise.reject(response[1]);
10+
else
11+
promise.reject(dop.core.getRejectError(rejection));
12+
}
13+
};

0 commit comments

Comments
 (0)