Skip to content

Commit

Permalink
Fix: getDirectory on node should auto subscribe to child modification
Browse files Browse the repository at this point in the history
  • Loading branch information
dufourgilles committed May 27, 2019
1 parent cc6a04e commit 66578f0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
4 changes: 4 additions & 0 deletions ember.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ TreeNode.prototype.addChild = function(child) {
this.children.push(child);
}

TreeNode.prototype.isNode = function() {
return ((this instanceof Node) || (this instanceof QualifiedNode));
}

TreeNode.prototype.isMatrix = function() {
return ((this instanceof MatrixNode) || (this instanceof QualifiedMatrix));
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "emberplus",
"version": "1.7.22",
"version": "1.7.23",
"description": "Javascript implementation of the Ember+ automation protocol",
"main": "index.js",
"scripts": {
Expand Down
13 changes: 13 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,19 @@ TreeServer.prototype.handleGetDirectory = function(client, element) {
// report their value changes automatically.
this.subscribe(client, element);
}
else if (element.isNode()) {
const children = element.getChildren();
if (children != null) {
for (let i = 0; i < children.length; i++) {
const child = children[i];
if ((child.isMatrix() || child.isParameter()) &&
(!child.isStream())) {
this.subscribe(client, child);
}
}
}
}

let res = this.getQualifiedResponse(element);
if (this._debug) {
console.log("getDirectory response", res);
Expand Down
9 changes: 5 additions & 4 deletions test/Server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const DeviceTree = require("../").DeviceTree;


const LOCALHOST = "127.0.0.1";
const PORT = 9008;
const PORT = 9009;


const init = function(_src,_tgt) {
Expand Down Expand Up @@ -90,7 +90,7 @@ describe("server", function() {

describe("JSONtoTree", function() {
let jsonTree;
before(function() {
beforeAll(function() {
jsonTree = init();
});
it("should generate an ember tree from json", function() {
Expand All @@ -106,7 +106,7 @@ describe("server", function() {

describe("Server - Client communication", function() {
let server,client;
before(function() {
beforeAll(function() {
jsonTree = init();
const root = TreeServer.JSONtoTree(jsonTree);
server = new TreeServer(LOCALHOST, PORT, root);
Expand All @@ -115,7 +115,7 @@ describe("server", function() {
console.log("server listening");
});
});
after(function() {
afterAll(function() {
client.disconnect();
server.close();
})
Expand All @@ -142,6 +142,7 @@ describe("server", function() {
.then(() => {
expect(client.root.elements[0].children[0].children.length).toBe(4);
expect(client.root.elements[0].children[0].children[3].contents.identifier).toBe("author");
expect(server.subscribers["0.0.0"]).toBeDefined();
});
});
});
Expand Down

0 comments on commit 66578f0

Please sign in to comment.