Skip to content

Fix multiple typescript/sass watchers #3332

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

Merged
merged 2 commits into from
Jan 24, 2018

Conversation

Mitko-Kerezov
Copy link
Contributor

Whenever using CLI as a library, calling livesync multiple times leads to multiple typescript/sass watchers.
This happens due to the fact that currentWatcherInfo.pattern is an array and checking two arrays for equality with !== is bound to return true at all times. toString() both arrays and check the string literals instead.

Ping @KristianDD @rosen-vladimirov

@Mitko-Kerezov Mitko-Kerezov self-assigned this Jan 23, 2018
@@ -527,7 +527,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi

const currentWatcherInfo = this.liveSyncProcessesInfo[liveSyncData.projectDir].watcherInfo;

if (!currentWatcherInfo || currentWatcherInfo.pattern !== pattern) {
if (!currentWatcherInfo || currentWatcherInfo.pattern.toString() !== pattern.toString()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be good to sort the array (if its an array) so that the order of patterns doesn't matter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, pattern is always an array as it can be seen here. currentWatcherInfo.pattern on the other hand is always an array too as it is actually the same pattern .

So there is no need to sort the array, as both arrays always have the same order.

@KristianDD what do you think?

Copy link
Contributor

@KristianDD KristianDD Jan 23, 2018

Choose a reason for hiding this comment

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

@Mitko-Kerezov But as seen here it can be a string. And as I will add configurations for livesync the patterns might change.

@Mitko-Kerezov Mitko-Kerezov force-pushed the kerezov/multiple-ts-watchers branch from f553e9c to a6165ec Compare January 24, 2018 09:07
@Mitko-Kerezov
Copy link
Contributor Author

Ping @KristianDD and @rosen-vladimirov. In light of @KristianDD's suggestion I decided to take a different approach to this.

Whenever using CLI as a library, calling livesync multiple times leads to multiple typescript/sass watchers.
This happens due to the fact that `currentWatcherInfo.pattern` is an array and checking two arrays for equality with `!==` is bound to return `true` at all times. `toString()` both arrays and check the string literals instead.
@Mitko-Kerezov Mitko-Kerezov force-pushed the kerezov/multiple-ts-watchers branch from a6165ec to 3f01716 Compare January 24, 2018 09:11
@@ -526,8 +526,8 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
}

const currentWatcherInfo = this.liveSyncProcessesInfo[liveSyncData.projectDir].watcherInfo;

if (!currentWatcherInfo || currentWatcherInfo.pattern !== pattern) {
const areWatcherPatternsDifferent = () => _.difference(currentWatcherInfo.pattern, pattern).length || _.difference(pattern, currentWatcherInfo.pattern).length;
Copy link
Contributor

Choose a reason for hiding this comment

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

You might use _.xor(currentWatcherInfo.pattern, pattern).length (not sure, should be checked).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was looking for this, thanks!

@@ -60,7 +60,7 @@ interface ILiveSyncProcessInfo {
timer: NodeJS.Timer;
watcherInfo: {
watcher: IFSWatcher,
pattern: string | string[]
pattern: string[]
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional: would look better if the property is called patterns.

@Mitko-Kerezov Mitko-Kerezov merged commit 0126afc into release Jan 24, 2018
@Mitko-Kerezov Mitko-Kerezov deleted the kerezov/multiple-ts-watchers branch January 24, 2018 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants