Skip to content

Commit e81ef53

Browse files
committed
Subscription implemented
1 parent e77ec7f commit e81ef53

File tree

10 files changed

+151
-210
lines changed

10 files changed

+151
-210
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
dop.core.configureRemoteFunctions = function(node, object, object_owner_id) {
2+
dop.util.path(object, function(source, prop, value, destiny, path) {
3+
if (
4+
isFunction(value) &&
5+
value._name == dop.cons.REMOTE_FUNCTION_UNSETUP
6+
) {
7+
dop.set(source, prop, value(node, object_owner_id, path.slice(0)))
8+
}
9+
})
10+
}

src/protocol/_onbroadcast.js

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

src/protocol/_onsubscribe.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,3 @@ dop.protocol._onsubscribe = function(node, request_id, request, response) {
4848
}
4949
}
5050
}
51-
52-
dop.core.configureRemoteFunctions = function(node, object, object_owner_id) {
53-
dop.util.path(
54-
object,
55-
function(source, prop, value, destiny, path) {
56-
console.log(prop, object_owner_id, path.slice(0))
57-
if (
58-
isFunction(value) &&
59-
value._name == dop.cons.REMOTE_FUNCTION_UNSETUP
60-
) {
61-
// dop.set(source, prop, value(node, object_owner_id, path.slice(0)))
62-
}
63-
},
64-
{}
65-
)
66-
}

src/protocol/broadcast.js

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

src/protocol/call.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
dop.protocol.call = function(node, object_id, path, params) {
2-
var object_data = dop.data.object[object_id]
3-
4-
if (
5-
isObject(object_data) &&
6-
isObject(object_data.node[node.token]) &&
7-
object_data.node[node.token].owner > 0
8-
) {
1+
dop.protocol.call = function(node, object_owner_id, path, params) {
2+
var owner = node.owner[object_owner_id]
3+
if (isObject(owner)) {
94
params = Array.prototype.slice.call(params, 0)
105
var request = dop.core.createRequest(
116
node,
127
dop.protocol.instructions.call,
13-
object_data.node[node.token].owner,
8+
object_owner_id,
149
path,
1510
params
1611
)

src/protocol/onbroadcast.js

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

src/protocol/oncall.js

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,57 @@
1-
dop.protocol.oncall = function(node, request_id, request) {
2-
dop.protocol.onfunction(node, request_id, request, request[1], function(
3-
permission
4-
) {
5-
return permission.subscriber === 1
6-
})
1+
dop.protocol.oncall = function(node, request_id, request, object_id) {
2+
var path = request[2],
3+
params = request[3],
4+
subscriber = node.subscriber[object_id]
5+
6+
if (isObject(subscriber)) {
7+
var function_name = path.pop(),
8+
object = dop.util.get(subscriber.object, path),
9+
f = object[function_name]
10+
11+
if (isFunction(f)) {
12+
function resolve(value) {
13+
var response = dop.core.createResponse(request_id, 0)
14+
if (value !== undefined) response.push(value)
15+
dop.core.storeAndSendRequests(node, response)
16+
return value
17+
}
18+
function reject(err) {
19+
dop.core.storeAndSendRequests(
20+
node,
21+
dop.core.createResponse(
22+
request_id,
23+
dop.core.error.reject_remote.CUSTOM_REJECTION,
24+
err
25+
)
26+
)
27+
}
28+
29+
if (dop.isRemoteFunction(f))
30+
f.apply(null, params)
31+
.then(resolve)
32+
.catch(reject)
33+
else
34+
dop.core.localProcedureCall(
35+
f,
36+
params,
37+
resolve,
38+
reject,
39+
function(req) {
40+
req.node = node
41+
return req
42+
},
43+
dop.getObjectProxy(object)
44+
)
45+
46+
return
47+
}
48+
}
49+
50+
dop.core.storeAndSendRequests(
51+
node,
52+
dop.core.createResponse(
53+
request_id,
54+
dop.core.error.reject_remote.FUNCTION_NOT_FOUND
55+
)
56+
)
757
}

src/protocol/onfunction.js

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

src/util/path.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ dop.util.pathRecursive = function(
4646
skip !== true &&
4747
value !== source &&
4848
circular.indexOf(value) == -1 &&
49-
(has_destiny && destiny[prop] !== undefined)
49+
// ((has_destiny && destiny[prop] !== undefined) ||
50+
source[prop] !== undefined
5051
) {
5152
circular.push(value)
5253
dop.util.pathRecursive(

0 commit comments

Comments
 (0)