Skip to content

Commit

Permalink
Consistent return value from target-manager.getTargets
Browse files Browse the repository at this point in the history
It should always return a Promise.

Fixes #420
  • Loading branch information
noseglid committed May 13, 2016
1 parent 0c3106e commit f8ed360
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/target-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ class TargetManager extends EventEmitter {
const activeTarget = this.getActiveTarget(path);
activeTarget && this.targetsView.setActiveTarget(activeTarget.name);

const targetNames = this.getTargets(path).map(t => t.name);
this.targetsView && this.targetsView.setItems(targetNames);
this.getTargets(path)
.then(targets => targets.map(t => t.name))
.then(targetNames => this.targetsView && this.targetsView.setItems(targetNames));
}

selectActiveTarget() {
Expand Down Expand Up @@ -198,13 +199,13 @@ class TargetManager extends EventEmitter {
getTargets(path) {
const pathTarget = this.pathTargets.find(pt => pt.path === path);
if (!pathTarget) {
return [];
return Promise.resolve([]);
}

if (pathTarget.targets.length === 0) {
return this.refreshTargets([ pathTarget.path ]).then(() => pathTarget.targets);
}
return pathTarget.targets;
return Promise.resolve(pathTarget.targets);
}

getActiveTarget(path) {
Expand Down

0 comments on commit f8ed360

Please sign in to comment.