Skip to content

Commit

Permalink
dependency-nest removed
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelly Selden committed Jun 4, 2016
1 parent 289ef72 commit 14554af
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 126 deletions.
84 changes: 0 additions & 84 deletions app/components/dependency-nest.js

This file was deleted.

66 changes: 64 additions & 2 deletions app/components/dependency-row.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import Ember from 'ember';
import { task } from 'ember-concurrency';
import sum from 'ember-cpm/macros/sum';
import promiseAll from 'ember-awesome-macros/promise-all';
import promiseArray from 'ember-awesome-macros/promise-array';
import getRealVersion from '../utils/get-real-version';
import mergeModules from '../utils/merge-modules';

const {
Component,
Expand All @@ -25,6 +28,10 @@ export default Component.extend({

parentDependencies: newArray(),

_numberOfAwaitingRequests: 0,

childNestingLevel: sum('nestingLevel', 1),

childDependencies: computed('parentDependencies.length', 'module', 'firstVersion', 'secondVersion', function() {
let parentDependencies = get(this, 'parentDependencies');
let module = get(this, 'module');
Expand Down Expand Up @@ -67,7 +74,7 @@ export default Component.extend({
}).length;

if (hasCircularReference) {
this.send('doneCrawling');
this.sendAction('doneCrawling');
}

return hasCircularReference;
Expand Down Expand Up @@ -171,9 +178,64 @@ export default Component.extend({
return firstVersion !== secondVersion;
}),

firstDependencies: computed('module', 'firstVersion', 'hasFirstCircularReference', 'stopCrawling', function() {
return get(this, 'getDependenciesTask').perform('firstVersion', 'hasFirstCircularReference');
}),
secondDependencies: computed('module', 'secondVersion', 'hasSecondCircularReference', 'stopCrawling', function() {
return get(this, 'getDependenciesTask').perform('secondVersion', 'hasSecondCircularReference');
}),
getDependenciesTask: task(function * (versionProp, circularReferenceProp) {
let module = get(this, 'module');
let version = get(this, versionProp);
let hasCircularReference = get(this, circularReferenceProp);
let stopCrawling = get(this, 'stopCrawling');
if (!module || !version || hasCircularReference || stopCrawling) {
return;
}

try {
let dependencies = yield get(this, 'task.getDependencies').perform(module, version);

return dependencies;
} catch (e) {
set(this, 'nestedError', e);
}
}),

dependenciesPromise: promiseAll('firstDependencies', 'secondDependencies'),

nestedDependencies: promiseArray('dependenciesPromise', function() {
return get(this, 'dependenciesPromise').then(([
firstDependencies,
secondDependencies
]) => {
if (!firstDependencies || !secondDependencies) {
return [];
}

let dependencies = mergeModules(
firstDependencies,
secondDependencies
);

if (!dependencies.length) {
this.sendAction('doneCrawling');
} else {
this.incrementProperty('_numberOfAwaitingRequests', dependencies.length);
}

return dependencies;
}).catch(() => {
// canceled task(s)
return [];
});
}),

actions: {
doneCrawling() {
this.sendAction('doneCrawling', get(this, 'dependency'));
if (this.decrementProperty('_numberOfAwaitingRequests') === 0) {
this.sendAction('doneCrawling');
}
}
}
});
17 changes: 0 additions & 17 deletions app/templates/components/dependency-nest.hbs

This file was deleted.

31 changes: 17 additions & 14 deletions app/templates/components/dependency-row.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,22 @@
</td>
</tr>
{{#unless hasBothCircularReference}}
{{dependency-nest
module=module
incomingNestingLevel=nestingLevel
repoWorkingDate=repoWorkingDate
repoBrokenDate=repoBrokenDate
firstVersion=firstVersion
secondVersion=secondVersion
parentDependencies=childDependencies
hasFirstCircularReference=hasFirstCircularReference
hasSecondCircularReference=hasSecondCircularReference
stopCrawling=stopCrawling
shouldOnlyShowDifferent=shouldOnlyShowDifferent
doneCrawling="doneCrawling"
}}
{{#each nestedDependencies as |dependency|}}
{{dependency-row
dependency=dependency
nestingLevel=childNestingLevel
repoWorkingDate=repoWorkingDate
repoBrokenDate=repoBrokenDate
parentDependencies=childDependencies
hasFirstCircularReferenceFromParent=hasFirstCircularReference
hasSecondCircularReferenceFromParent=hasSecondCircularReference
stopCrawling=stopCrawling
shouldOnlyShowDifferent=shouldOnlyShowDifferent
doneCrawling="doneCrawling"
}}
{{/each}}
{{#if nestedError}}
<tr><td>{{nestedError}}</td></tr>
{{/if}}
{{/unless}}
{{/unless}}
17 changes: 8 additions & 9 deletions tests/integration/components/dependency-row-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ test('doesn\'t make request if no module', function(assert) {

delete dependency['module'];

let called = false;
let called;
versionsCallback = () => {
called = true;
};
Expand Down Expand Up @@ -242,7 +242,7 @@ test('handles failed request', function(assert) {
return [500, {}, {}];
};

let called = false;
let called;
onDoneCrawling = () => {
called = true;
};
Expand Down Expand Up @@ -387,17 +387,16 @@ test('versions are different', function(assert) {
test('sends action when done', function(assert) {
assert.expect(1);

onDoneCrawling = dependency => {
assert.deepEqual(dependency, {
module: 'test-module',
firstVersionHint: testFirstVersionHint,
secondVersionHint: testSecondVersionHint
});
let called;
onDoneCrawling = () => {
called = true;
};

render.call(this);

return wait();
return wait().then(() => {
assert.ok(called);
});
});

test('shows child dependencies', function(assert) {
Expand Down

0 comments on commit 14554af

Please sign in to comment.