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

allow computed artifacts to request other computed artifacts #2018

Merged
merged 2 commits into from
Apr 18, 2017

Conversation

brendankenny
Copy link
Member

There's no reason that a computed artifact shouldn't be able to access other computed artifacts using the same artifact that it received. Since it can't access any new artifacts, just things based on the artifact it's already received, the cache will still work and computation of audits->requiredArtifacts->required gatherers still works.

should fulfill the needs of #2013

I've made a ComputedArtifacts type for this object, and had Artifacts extend it. Originally I was going to do that for the actual artifact object as well (make the computedArtifact object the prototype of the artifact object), but realized it wasn't necessary.

@brendankenny
Copy link
Member Author

brendankenny commented Apr 15, 2017

Originally I was going to do that for the actual artifact object as well (make the computedArtifact object the prototype of the artifact object), but realized it wasn't necessary.

on the other hand, Object.assign() not altering computedArtifacts depends on the order in which its called, so maybe this should switch to the more explicit Object.create() (which could even be tested)...

if (this.cache.has(artifact)) {
return Promise.resolve(this.cache.get(artifact));
if (this._cache.has(artifact)) {
return Promise.resolve(this._cache.get(artifact));
}

return Promise.resolve().then(_ => this.compute_(artifact)).then(computedArtifact => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

don't you need to pass it in here?

Copy link
Member Author

Choose a reason for hiding this comment

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

don't you need to pass it in here?

er, yeah, probably kind of important :)

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@brendankenny
Copy link
Member Author

PTAL

static instantiateComputedArtifacts() {
const computedArtifacts = {};
require('fs').readdirSync(path.join(__dirname, 'computed')).forEach(function(file) {
// Drop `.js` suffix to keep browserify import happy.
file = file.replace(/\.js$/, '');
const ArtifactClass = require('./computed/' + file);
const artifact = new ArtifactClass();
const artifact = new ArtifactClass(computedArtifacts);
Copy link
Collaborator

Choose a reason for hiding this comment

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

really not a fan of this intertwined computedArtifacts, artifact object, but I guess it works for now

Copy link
Member Author

Choose a reason for hiding this comment

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

really not a fan of this intertwined computedArtifacts, artifact object, but I guess it works for now

sure, it uses inheritance for delegation, but on the plus side it guarantees invariants on our artifact dependency graph and it's nicely isolated, so it's ready for an easy refactor at any time :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants