Skip to content

Commit 66578f0

Browse files
committed
Fix: getDirectory on node should auto subscribe to child modification
1 parent cc6a04e commit 66578f0

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

ember.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ TreeNode.prototype.addChild = function(child) {
149149
this.children.push(child);
150150
}
151151

152+
TreeNode.prototype.isNode = function() {
153+
return ((this instanceof Node) || (this instanceof QualifiedNode));
154+
}
155+
152156
TreeNode.prototype.isMatrix = function() {
153157
return ((this instanceof MatrixNode) || (this instanceof QualifiedMatrix));
154158
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "emberplus",
3-
"version": "1.7.22",
3+
"version": "1.7.23",
44
"description": "Javascript implementation of the Ember+ automation protocol",
55
"main": "index.js",
66
"scripts": {

server.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,19 @@ TreeServer.prototype.handleGetDirectory = function(client, element) {
382382
// report their value changes automatically.
383383
this.subscribe(client, element);
384384
}
385+
else if (element.isNode()) {
386+
const children = element.getChildren();
387+
if (children != null) {
388+
for (let i = 0; i < children.length; i++) {
389+
const child = children[i];
390+
if ((child.isMatrix() || child.isParameter()) &&
391+
(!child.isStream())) {
392+
this.subscribe(client, child);
393+
}
394+
}
395+
}
396+
}
397+
385398
let res = this.getQualifiedResponse(element);
386399
if (this._debug) {
387400
console.log("getDirectory response", res);

test/Server.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const DeviceTree = require("../").DeviceTree;
44

55

66
const LOCALHOST = "127.0.0.1";
7-
const PORT = 9008;
7+
const PORT = 9009;
88

99

1010
const init = function(_src,_tgt) {
@@ -90,7 +90,7 @@ describe("server", function() {
9090

9191
describe("JSONtoTree", function() {
9292
let jsonTree;
93-
before(function() {
93+
beforeAll(function() {
9494
jsonTree = init();
9595
});
9696
it("should generate an ember tree from json", function() {
@@ -106,7 +106,7 @@ describe("server", function() {
106106

107107
describe("Server - Client communication", function() {
108108
let server,client;
109-
before(function() {
109+
beforeAll(function() {
110110
jsonTree = init();
111111
const root = TreeServer.JSONtoTree(jsonTree);
112112
server = new TreeServer(LOCALHOST, PORT, root);
@@ -115,7 +115,7 @@ describe("server", function() {
115115
console.log("server listening");
116116
});
117117
});
118-
after(function() {
118+
afterAll(function() {
119119
client.disconnect();
120120
server.close();
121121
})
@@ -142,6 +142,7 @@ describe("server", function() {
142142
.then(() => {
143143
expect(client.root.elements[0].children[0].children.length).toBe(4);
144144
expect(client.root.elements[0].children[0].children[3].contents.identifier).toBe("author");
145+
expect(server.subscribers["0.0.0"]).toBeDefined();
145146
});
146147
});
147148
});

0 commit comments

Comments
 (0)