-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Conversation
on the other hand, |
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 => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 :)
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 hadArtifacts
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.