Skip to content

Commit 1f18a79

Browse files
committed
Small changes for onsubscribe and added version on mutation instruction to be implemented on protocol
1 parent 4f63bbe commit 1f18a79

File tree

8 files changed

+623
-376
lines changed

8 files changed

+623
-376
lines changed

dist/browser.js

Lines changed: 303 additions & 174 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: 282 additions & 174 deletions
Large diffs are not rendered by default.

src/core/error.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ dop.core.error = {
66
},
77

88
reject: {
9-
// OBJECT_NAME_NOT_FOUND: 1,
10-
// 1: 'Object "%s" not found to be subscribed',
11-
// OBJECT_ALREADY_SUBSCRIBED: 2,
12-
// 2: 'The object "%s" is already subscribed',
9+
OBJECT_NOT_FOUND: 'Object not found to be subscribed',
10+
// OBJECT_ALREADY_SUBSCRIBED: 'The object "%s" is already subscribed',
1311
}
1412

1513
};

src/core/objects/setAction.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ dop.core.setActionMutator = function(destiny, prop, value, typeofValue, path) {
6666
// Set array and skip path deep
6767
else if (typeofValue=='array') {
6868
dop.set(destiny, prop, dop.util.merge([], value));
69-
return true;
69+
return true; // Skiping to dont go inside
7070
}
7171

7272
// Set array and skip path deep
7373
else if (typeofValue=='object' && typeofDestiny!='object' && typeofDestiny!='array') {
7474
dop.set(destiny, prop, dop.util.merge({}, value));
75-
return true;
75+
return true; // Skiping to dont go inside
7676
}
7777

7878
// Set value

src/protocol/_onsubscribe.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,34 @@ dop.protocol._onsubscribe = function(node, request_id, request, response) {
77
request.promise.reject(dop.core.getRejectError(response[0], request[2]));
88

99
else {
10-
var object_path = response[1],
10+
var object_path = typeof response[1]=='number' ? [response[1]] : response[1],
1111
object_owner_id = object_path[0],
1212
object_owner = response[2],
1313
object;
14-
15-
if (node.object_owner[object_owner_id] === undefined) {
16-
var collector = dop.collectFirst();
17-
object = dop.register((dop.isObjectRegistrable(request.into)) ?
18-
dop.core.setAction(request.into, object_owner)
14+
15+
if (!isArray(object_path) || typeof object_owner_id!='number')
16+
request.promise.reject(dop.core.error.reject.OBJECT_NOT_FOUND);
17+
18+
else {
19+
if (node.object_owner[object_owner_id] === undefined) {
20+
var collector = dop.collectFirst();
21+
object = dop.register((dop.isObjectRegistrable(request.into)) ?
22+
dop.core.setAction(request.into, object_owner)
23+
:
24+
object_owner);
25+
dop.core.registerOwner(node, object, object_owner_id);
26+
collector.emitAndDestroy();
27+
}
28+
else
29+
object = dop.data.object[node.object_owner[object_owner_id]].object;
30+
31+
object = dop.util.get(object, object_path.slice(1));
32+
33+
(!isObject(object)) ?
34+
request.promise.reject(dop.core.error.reject.OBJECT_NOT_FOUND)
1935
:
20-
object_owner);
21-
dop.core.registerOwner(node, object, object_owner_id);
22-
collector.emitAndDestroy();
36+
request.promise.resolve(object);
2337
}
24-
else
25-
object = dop.data.object[node.object_owner[object_owner_id]].object;
26-
27-
28-
request.promise.resolve(dop.util.get(object, object_path.slice(1)));
2938
}
3039
}
3140

src/protocol/instructions.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ dop.protocol.instructions = {
55
// [<request_id>, <instruction>, <params...>]
66
// If <request_id> it's greater than 0 is a request, if is less than 0 then is the response of the request.
77

8-
// Is possible send multiple requests in one message, just wrapping it in an Array. But the order of the responses is not in order. Which means the response of request_idTwo could be resolved before request_idOne
8+
// Is possible send multiple requests in one message, just wrapping it in an Array. But the order of the responses is not determined. Which means the response of request_idTwo could be resolved before request_idOne
99
// [[<request_id1>, <instruction>, <params...>], [<request_id2>, <instruction>, <params...>]]
1010

1111
// Is possible send one request with multiple instructions. The response will be recieved when all the requests are resolved. The response could be only one. But if the response is multiple has to respect the order
@@ -25,24 +25,26 @@ dop.protocol.instructions = {
2525

2626

2727
// Server -> Client
28-
connect: 0, // [ 1234, <instruction>, <user_token>, <options>]
28+
connect: 0, // [ 1234, <instruction>, <user_token>]
2929
// [-1234, 0]
3030

3131
// Subscriptor -> Owner
3232
subscribe: 1, // [ 1234, <instruction>, <params...>]
33-
// [-1234, 0, [<object_id>], <data_object>]
33+
// [-1234, 0, <object_id>, <data_object>]
3434
// [-1234, 0, [<object_id>, 'path']]
3535

3636
// Subscriptor -> Owner
3737
unsubscribe: 2, // [ 1234, <instruction>, <object_id>]
38+
// Owner -> Subscriptor
39+
// [ 1234, <instruction>, -<object_id>]
3840
// [-1234, 0]
3941

4042
// Subscriptor -> Owner
41-
call: 3, // [ 1234, <instruction>, [<object_id>,'path','path'], [<params...>]]
43+
call: 3, // [ 1234, <instruction>, <object_id>, ['path','path'], [<params...>]]
4244
// [-1234, 0, <return>]
4345

4446
// Owner -> Subscriptor
45-
mutation: 4, // [ 1234, <instruction>, <object_id>, <object_data_to_merge>]
47+
mutation: 4, // [ 1234, <instruction>, <object_id>, <version>, <mutation>]
4648
// [-1234, 0]
4749
};
4850

src/protocol/onsubscribe.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ dop.protocol.onsubscribe = function(node, request_id, request) {
1010
var object = dop.register(value),
1111
object_id = dop.getObjectId(object),
1212
object_root = dop.getObjectRoot(object),
13-
response = dop.core.createResponse(request_id, 0, dop.getObjectDop(object));
13+
object_dop = dop.getObjectDop(object),
14+
response = dop.core.createResponse(request_id, 0, object_dop.length==1 ? object_dop[0] : object_dop);
1415

1516
if (dop.core.registerSubscriber(node, object_root))
1617
response.push(object_root);

0 commit comments

Comments
 (0)