mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-09 01:32:34 -05:00
replaced watch with watchFile (#9873)
* replaced watch with watchFile * testing debounce * changed the beounce delay to 1500
This commit is contained in:
@@ -8,7 +8,6 @@ import * as vscode from 'vscode';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs-extra';
|
||||
import * as constants from '../common/constants';
|
||||
import * as fsw from 'fs';
|
||||
import { IPrompter, QuestionTypes, IQuestion } from '../prompts/question';
|
||||
import CodeAdapter from '../prompts/adapter';
|
||||
import { BookTreeItem, BookTreeItemType } from './bookTreeItem';
|
||||
@@ -19,6 +18,7 @@ import * as loc from '../common/localizedConstants';
|
||||
import { ApiWrapper } from '../common/apiWrapper';
|
||||
import * as glob from 'fast-glob';
|
||||
import { isNullOrUndefined } from 'util';
|
||||
import { debounce } from '../common/utils';
|
||||
|
||||
const Content = 'content';
|
||||
|
||||
@@ -126,13 +126,12 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
|
||||
// add file watcher on toc file.
|
||||
if (!isNotebook) {
|
||||
fsw.watch(path.join(this.currentBook.bookPath, '_data', 'toc.yml'), async (event, filename) => {
|
||||
if (event === 'change') {
|
||||
let changedBook = this.books.find(book => book.bookPath === bookPath);
|
||||
await changedBook.initializeContents().then(() => {
|
||||
this._onDidChangeTreeData.fire(changedBook.bookItems[0]);
|
||||
});
|
||||
this._onDidChangeTreeData.fire();
|
||||
fs.watchFile(path.join(bookPath, '_data', 'toc.yml'), async (curr, prev) => {
|
||||
if (curr.mtime > prev.mtime) {
|
||||
let book = this.books.find(book => book.bookPath === bookPath);
|
||||
if (book) {
|
||||
this.fireBookRefresh(book);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -141,6 +140,13 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
}
|
||||
}
|
||||
|
||||
@debounce(1500)
|
||||
async fireBookRefresh(book: BookModel): Promise<void> {
|
||||
await book.initializeContents().then(() => {
|
||||
this._onDidChangeTreeData.fire();
|
||||
});
|
||||
}
|
||||
|
||||
async closeBook(book: BookTreeItem): Promise<void> {
|
||||
// remove book from the saved books
|
||||
let deletedBook: BookModel;
|
||||
@@ -160,7 +166,7 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider<BookTreeIte
|
||||
} finally {
|
||||
// remove watch on toc file.
|
||||
if (deletedBook && !deletedBook.isNotebook) {
|
||||
fsw.unwatchFile(path.join(deletedBook.bookPath, '_data', 'toc.yml'));
|
||||
fs.unwatchFile(path.join(deletedBook.bookPath, '_data', 'toc.yml'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user