-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core/local/chokidar: Extract separatePendingChanges() from analysis
- Loading branch information
Showing
2 changed files
with
68 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* @module core/local/chokidar/separate_pending_changes | ||
* @flow | ||
*/ | ||
|
||
const logger = require('../../utils/logger') | ||
|
||
/*:: | ||
import type { LocalChange } from './local_change' | ||
*/ | ||
|
||
const component = 'chokidar/separate_pending_changes' | ||
const log = logger({ component }) | ||
|
||
/** Push back pending changes. | ||
* | ||
* More low-level events are expected to come up for those changes to be | ||
* complete. They will be injected back in the next analysis run. | ||
* | ||
* This step helped us fix a bunch of move scenarios with unexpected event | ||
* batches. | ||
* | ||
* ## Known issues | ||
* | ||
* - May break events order. | ||
* - No timeout (some changes may be pending forever). | ||
*/ | ||
const separatePendingChanges = ( | ||
changes /*: LocalChange[] */, | ||
pendingChanges /*: LocalChange[] */ | ||
) /*: LocalChange[] */ => { | ||
log.trace('Reserve changes in progress for next flush...') | ||
|
||
for (let i = 0; i < changes.length; i++) { | ||
const change = changes[i] | ||
if (change.wip) { | ||
if (change.type === 'DirMove' || change.type === 'FileMove') { | ||
log.debug( | ||
{ | ||
change: change.type, | ||
oldpath: change.old.path, | ||
path: change.path, | ||
ino: change.ino | ||
}, | ||
'incomplete change' | ||
) | ||
} else { | ||
log.debug( | ||
{ change: change.type, path: change.path }, | ||
'incomplete change' | ||
) | ||
} | ||
pendingChanges.push(changes[i]) | ||
} else { | ||
log.debug(`Identified ${changes.length} change(s).`) | ||
log.debug(`${pendingChanges.length} of them are still pending.`) | ||
return changes.slice(i) | ||
} | ||
} | ||
// All actions are WIP | ||
return [] | ||
} | ||
|
||
module.exports = { | ||
separatePendingChanges | ||
} |