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

feat(tools): do not invoke tasks if not necessary #1443

Merged
merged 1 commit into from
Oct 10, 2016
Merged

Conversation

mgechev
Copy link
Owner

@mgechev mgechev commented Oct 9, 2016

In dev executes tasks only when a specific file type has changed.
Fix #1432.

Copy link
Contributor

@robstoll robstoll left a 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) {
Copy link
Contributor

@robstoll robstoll Oct 9, 2016

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

Copy link
Contributor

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();
Copy link
Contributor

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`);
Copy link
Contributor

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);
Copy link
Contributor

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) => {
Copy link
Contributor

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));
Copy link
Contributor

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');
Copy link
Contributor

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'));
Copy link
Contributor

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 {
Copy link
Contributor

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);
}

Copy link
Contributor

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 {
Copy link
Contributor

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)

Copy link
Owner Author

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.

@mgechev mgechev force-pushed the task-perf branch 2 times, most recently from e558d18 to 65945b8 Compare October 9, 2016 19:03
@mgechev
Copy link
Owner Author

mgechev commented Oct 9, 2016

@robstoll thanks for the review! It seems vim messed the indentation up during the rebase I did. shallRun is more clear so I renamed it too.

Copy link
Contributor

@Bigous Bigous left a 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.
@mgechev mgechev merged commit 730fb41 into master Oct 10, 2016
@mgechev mgechev deleted the task-perf branch October 10, 2016 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants