constructor(props) { super(props); this.state = { newCommentId: 1, saveCommentLikeStatus: null, threads: [], commentEditing: { commentId: null, sending: false }, reply: { commentId: null, sending: false }, showFocus: false, sending: false, loadingComments: false, status: "", animation: false, }; this.lastThreadRef = React.createRef(); this.commentsListRef = React.createRef(); this.debouncedSendData = debounce(this.sendData, 300); }
startFileWatcher () { if ( this._active || this.static ) { return; } this._active = true; // this is a file watch that isn't fully initialized if ( this._deferred ) { this._makeReady(); } // make sure the file is in the appropriate target directory to start if ( this.file ) { linkSync( this.file ).to( this.targetFile ); } let changed = []; const relay = debounce( () => { this.changes = changed.map( change => { const result = { file: relative( this.dir, change.path ) }; change.type === 'add' && ( change.added = true ); change.type === 'change' && ( change.changed = true ); change.type === 'unlink' && ( change.removed = true ); return result; }); this.emit( 'invalidate', this.changes ); changed = []; }, 100 ); const options = { persistent: true, ignoreInitial: true, useFsEvents: false // see https://github.com/paulmillr/chokidar/issues/146 }; if ( this.dir ) { this._watcher = watch( this.dir, options ); [ 'add', 'change', 'unlink' ].forEach( type => { this._watcher.on( type, path => { changed.push({ type, path }); relay(); }); }); } if ( this.file ) { this._fileWatcher = watch( this.file, options ); this._fileWatcher.on( 'change', () => { link( this.file ).to( this.targetFile ); }); } }