All files / app/actions vscode.ts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47          5x   5x   5x           4x 4x                                                            
import { receiveCommits, receiveCommitRange } from 'app/actions/commits';
import { receiveDiff } from 'app/actions/diff';
import { debug } from 'app/utilities/logger';
 
// @ts-ignore
export const isVscode = window && window.IS_VSCODE_WEBVIEW;
// @ts-ignore
export const vscode = isVscode ? acquireVsCodeApi() : null;
 
Iif (isVscode) {
  debug('running in VSCode.');
}
 
export function handleVscodeMessages(dispatch) {
  // @ts-ignore
  Eif (!window || !window.IS_VSCODE_WEBVIEW) {
    return;
  }
  window.addEventListener('message', event => {
    const { data } = event;
    debug(`actions/vscode received window message`, {
      ...data,
      // don't dump full commits or file contents to log
      commits: data.commits ? `object[${data.commits.length}]` : undefined,
      leftFileContents: redactArray(data.leftFileContents),
      rightFileContents: redactArray(data.rightFileContents),
      modifiedFiles: redactArray(data.modifiedFiles),
    });
 
    switch (data.type) {
      case 'commitRange':
        dispatch(receiveCommitRange(data.path, data));
        break;
      case 'history':
        dispatch(receiveCommits(data.path, data));
        break;
      case 'diff':
        dispatch(receiveDiff(data.path, data));
        break;
    }
  });
}
 
function redactArray(array) {
  return array ? `[..] length=${array.length}` : undefined;
}