Skip to content

Commit 20c206f

Browse files
committed
Renamed mutation -> patche on protocol, and building it
1 parent 9971826 commit 20c206f

File tree

9 files changed

+68
-23
lines changed

9 files changed

+68
-23
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules/
22
npm-debug.log
33
.vscode
4-
test*.js
4+
test*.js
5+
log

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@
5757
"scripts": {
5858
"grunt": "grunt",
5959
"build": "grunt --build",
60-
"test": "tap test/**.js test/transports/**.js",
60+
"test": "tap test/**.js test/protocol/**.js",
6161
"test-electron": "browserify test/*.js | tape-run --render=\"faucet\"",
6262
"test-chrome": "browserify test/*.js | tape-run --render=\"faucet\" --browser chrome",
6363
"test-safari": "browserify test/*.js | tape-run --render=\"faucet\" --browser safari",
6464
"test-firefox": "browserify test/*.js | tape-run --render=\"faucet\" --browser firefox",
65-
"test-websockets": "tap test/transports/**.js --test-arg=websockets",
66-
"test-socketio": "tap test/transports/**.js --test-arg=socketio",
67-
"test-sockjs": "tap test/transports/**.js --test-arg=sockjs",
68-
"test-local": "tap test/transports/**.js --test-arg=local"
65+
"test-websockets": "tap test/protocol/**.js --test-arg=websockets",
66+
"test-socketio": "tap test/protocol/**.js --test-arg=socketio",
67+
"test-sockjs": "tap test/protocol/**.js --test-arg=sockjs",
68+
"test-local": "tap test/protocol/**.js --test-arg=local"
6969
}
7070
}

src/core/error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dop.core.error = {
1313
// Remote rejects
1414
reject_remote: {
1515
OBJECT_NOT_FOUND: 1,
16-
1: 'Remote object not found or not permissions to be subscribed',
16+
1: 'Remote object not found or not permissions to use it',
1717
SUBSCRIPTION_NOT_FOUND: 2,
1818
2: 'Subscription not found to unsubscribe this object',
1919
FUNCTION_NOT_FOUND: 3,

src/core/protocol/emitNodes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dop.core.emitNodes = function(action) {
77
for (node_token in object_data.node) {
88
if (object_data.node[node_token].subscriber===1) {
99
node = dop.data.node[node_token];
10-
dop.protocol.mutation(node, object_id, action[object_id].action);
10+
dop.protocol.patch(node, Number(object_id), action[object_id].action);
1111
}
1212
}
1313
}

src/core/protocol/registerObjectToNode.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ dop.core.registerObjectToNode = function(node, object) {
1616
object_data.nodes_total += 1;
1717
object_data.node[node.token] = {
1818
subscriber: 0, // 0 or 1 || false true
19-
owner: 0, // object_id_owner
19+
owner: 0, // object_id_owner || 0 === false
2020
subscriber_version: 0,
21-
owner_version: 0
21+
owner_version: 0,
22+
pending_version: 0,
23+
pending: {}
2224
};
2325
}
2426

src/protocol/instructions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ dop.protocol.instructions = {
4141
// [-1234, 0, <return>]
4242

4343
// Owner -> Subscriptor
44-
mutation: 5, // [ 1234, <instruction>, <object_id>, <version>, <mutation>]
44+
patch: 5, // [ 1234, <instruction>, <object_id>, <version>, <patch>]
4545
// [-1234, 0]
4646
};
4747

src/protocol/mutation.js

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

src/protocol/patch.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
dop.protocol.patch = function(node, object_id, patch) {
3+
var object_node = dop.data.object[object_id].node[node.token],
4+
version = ++object_node.subscriber_version,
5+
request = dop.core.createRequest(
6+
node,
7+
dop.protocol.instructions.patch,
8+
object_id,
9+
version,
10+
patch
11+
);
12+
13+
object_node.pending[version] = patch;
14+
dop.core.storeSendMessages(node, request, dop.encodeFunction);
15+
return request.promise;
16+
};
17+
18+
dop.protocol.onpatch = function(node, request_id, request) {
19+
var object_id = request[1],
20+
version = request[2],
21+
patch = request[3],
22+
response = dop.core.createResponse(request_id),
23+
object_data = dop.data.object[object_id],
24+
object_node;
25+
26+
if (isObject(object_data) && isObject(object_data.node[node.token]) && object_data.node[node.token].owner===object_id) {
27+
object_node = object_data.node[node.token];
28+
if (object_node.owner_version+1 === version) {
29+
// We apply patch
30+
object_node.owner_version += 1;
31+
collector = dop.collectFirst();
32+
dop.core.setActionFunction(object_data.object, patch);
33+
collector.emitAndDestroy();
34+
response.push(0);
35+
}
36+
}
37+
else
38+
response.push(dop.core.error.reject_remote.OBJECT_NOT_FOUND);
39+
40+
dop.core.storeSendMessages(node, response);
41+
};
42+
43+
dop.protocol._onpatch = function(node, request_id, request, response) {
44+
var rejection = response[0],
45+
promise = request.promise;
46+
if (rejection !== undefined) {
47+
if (rejection === 0) {
48+
49+
promise.resolve(response[1]);
50+
}
51+
else
52+
promise.reject(dop.core.getRejectError(rejection));
53+
}
54+
};

0 commit comments

Comments
 (0)