Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix getDirectory for parameters #39

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions src/Ember/Client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,13 @@ export class EmberClient extends EventEmitter<EmberClientEvents> {
cb,
})

return this._sendCommand<RootElement>(node, command, ExpectResponse.HasChildren)
return this._sendCommand<RootElement>(
node,
command,
node.contents.type == 'PARAMETER'
? ExpectResponse.None
: ExpectResponse.HasChildren
)
}
async subscribe(
node: RootElement | Array<RootElement>,
Expand Down Expand Up @@ -388,24 +394,24 @@ export class EmberClient extends EventEmitter<EmberClientEvents> {
const i = pathArr.shift()
if (!i) break // TODO - this will break the loop if the path was `1..0`
if (!tree) break
let next = getNextChild(tree, i)
if (!next) {
const req = await this.getDirectory(tree)
tree = (await req.response) as NumberedTreeNode<EmberElement>
next = getNextChild(tree, i)
}
tree = next
const req = await this.getDirectory(tree)
tree = (await req.response) as NumberedTreeNode<EmberElement>
tree = getNextChild(tree, i)
Comment on lines +397 to +399

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you help me understand why this is needed in regards to the main issue this PR addresses?

The reason I am asking it makes it such that every time a library user uses this call the library will fetch all nodes in the path even though we have already fetched these before and can just look at them locally.

if (!tree) throw new Error(`Could not find node ${i} on given path ${numberedPath.join()}`)
if (tree?.number !== undefined) numberedPath.push(tree.number)
}

if (cb && numberedPath) {
this._subscriptions.push({
path: numberedPath.join('.'),
cb,
})
if (tree) {
const req = await this.getDirectory(tree)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constant is never used so it is not necessary to assign it

}

// this resulted in doubled subscription because getDirectory() adds the element as well

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what's going on here. Since the callback is never passed to the getDirectory call it should not cause a double subscription.

// if (cb && numberedPath) {
// this._subscriptions.push({
// path: numberedPath.join('.'),
// cb,
// })
// }

return tree
}

Expand Down
1 change: 0 additions & 1 deletion src/encodings/ber/encoder/Tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ function hasChildren(el: TreeElement<EmberElement>): boolean {
el.children !== undefined &&
!(
el.contents.type === ElementType.Command ||
el.contents.type === ElementType.Parameter ||
el.contents.type === ElementType.Template
)
)
Expand Down
Loading