-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat(tools): do not invoke tasks if not necessary #1443
Conversation
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.
Some thoughts
if (typeof task === 'function') { | ||
return new class AnonTask extends Task { | ||
run(done: any) { | ||
if (task.length > 0) { |
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.
indentation for the run method seems to be wrong starting from 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.
hm... here it looks good, not sure if it is a bug in the review view of github or if it is shown nicely here (the same for the other hints about indentation)
return taskReturnedValue; | ||
} | ||
|
||
done(); |
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.
ending here (indentation problem)
}; | ||
} | ||
throw new Error(`${taskName} should be instance of the class | ||
Task, a function or a class which extends Task`); |
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.
indentation problem as well
|
||
runSequence(taskname, () => { | ||
changeFileManager.clear(); | ||
notifyLiveReload(e); |
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.
Indentation problem
export abstract class CssTask extends Task { | ||
|
||
precondition(files: String[]) { | ||
return files.reduce((a, f) => { |
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.
couldn't all those reduce calls be simplified with files.some(f => f.endsWith('.css') || ...)
?
.pipe(gulp.dest(Config.APP_DEST)); | ||
}; | ||
return gulp.src(paths) | ||
.pipe(gulp.dest(Config.APP_DEST)); |
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.
indentation problem
|
||
precondition(files: String[]) { | ||
return super.precondition(files) || files.reduce((a, f) => { | ||
return a || f.endsWith('.html'); |
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.
indentation
precondition(files: String[]) { | ||
return files.reduce((a, f) => { | ||
return a || (!f.endsWith('.css') && !f.endsWith('.sass') && | ||
!f.endsWith('.scss') && !f.endsWith('.ts')); |
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.
I would indent this line once more
* | ||
* @param {string[]} files A list of files changed since the previous watch. | ||
*/ | ||
precondition(files: string[]): boolean { |
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.
I would name the method differently, something like shallRun
, would make its usage clearer IMO
if (task.shallRun(changeFileManager.lastChangedFiles)) {
return task.run(done);
}
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.
Maybe it's too late for this one, but I'll follow NG2 pattern and use a canRun
or something like that. Sorry, I was out today.
/** | ||
* Base class for all tasks. | ||
*/ | ||
export abstract class Task { |
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.
You could provide another abstract class which uses a regular expression to test file endings. This way a subclass would only need to pass an array of file endings to this abstract class instead of overridingprecondition
(shallRun
respectively, see below)
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.
Yes, I considered this idea here. It might be a good idea but I'd prefer to keep the API minimalistic for now. Maybe in future will turn out that the most important precondition is not related to file type.
e558d18
to
65945b8
Compare
@robstoll thanks for the review! It seems vim messed the indentation up during the rebase I did. |
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.
Legitimate.
In dev executes tasks only when a specific file type has changed. Fix #1432.
In dev executes tasks only when a specific file type has changed.
Fix #1432.