Repository: atom/atom
File: src/main-process/atom-window.js (JavaScript)

Code before:

  hasProjectPath () {
    return this.representedDirectoryPaths.length > 0
  }

  setupContextMenu () {
    const ContextMenu = require('./context-menu')

    this.browserWindow.on('context-menu', menuTemplate => {
      return new ContextMenu(menuTemplate, this)
    })
  }

  containsPaths (paths) {
    return paths.every(p => this.containsPath(p))
  }

  loadDataOverProcessBoundary () {
    Object.defineProperty(this.browserWindow, 'loadSettingsJSON', {
      get: () => JSON.stringify(Object.assign({
        userSettings: this.atomApplication.configFile.get(),
        projectSettings: this.projectSettings
      }, this.loadSettings)),
      configurable: true
    })
  }

  containsPath (pathToCheck) {
    if (!pathToCheck) return false
    let stat
    return this.representedDirectoryPaths.some(projectPath => {
      if (pathToCheck === projectPath) return true
      if (!pathToCheck.startsWith(path.join(projectPath, path.sep))) return false
      if (stat === undefined) stat = fs.statSyncNoException(pathToCheck)
      return !stat || !stat.isDirectory()
    })
  }

  handleEvents () {
    this.browserWindow.on('close', async event => {
      if (!this.atomApplication.quitting && !this.unloading) {
        event.preventDefault()
        this.unloading = true
        this.atomApplication.saveCurrentWindowOptions(false)
        if (await this.prepareToUnload()) this.close()
      }
    })

    this.browserWindow.on('closed', () => {
      this.fileRecoveryService.didCloseWindow(this)
      this.atomApplication.removeWindow(this)

Review comment (refactor):
The name `loadDataOver...` makes it sound like this method itself is going to load or retrieve some data, when really it just defines an accessor method that allows the window process to retrieve data later. It's hard to give this weird little code path a name; I might just leave the code un-abstracted in the constructor.

Another though - should we just define this getter using `get` syntax as a method? I can't remember why it needs to be configurable.

Code after:

    const hasPathToOpen = !(locationsToOpen.length === 1 && locationsToOpen[0].pathToOpen == null)
    if (hasPathToOpen && !this.isSpecWindow()) this.openLocations(locationsToOpen)
  }

  hasProjectPath () {
    return this.representedDirectoryPaths.length > 0
  }

  setupContextMenu () {
    const ContextMenu = require('./context-menu')

    this.browserWindow.on('context-menu', menuTemplate => {
      return new ContextMenu(menuTemplate, this)
    })
  }

  containsPaths (paths) {
    return paths.every(p => this.containsPath(p))
  }

  containsPath (pathToCheck) {
    if (!pathToCheck) return false
    let stat
    return this.representedDirectoryPaths.some(projectPath => {
      if (pathToCheck === projectPath) return true
      if (!pathToCheck.startsWith(path.join(projectPath, path.sep))) return false
      if (stat === undefined) stat = fs.statSyncNoException(pathToCheck)
      return !stat || !stat.isDirectory()
    })
  }

  handleEvents () {
    this.browserWindow.on('close', async event => {
      if (!this.atomApplication.quitting && !this.unloading) {
        event.preventDefault()
        this.unloading = true
        this.atomApplication.saveCurrentWindowOptions(false)
        if (await this.prepareToUnload()) this.close()
      }
    })

    this.browserWindow.on('closed', () => {
      this.fileRecoveryService.didCloseWindow(this)
      this.atomApplication.removeWindow(this)
      this.resolveClosedPromise()
    })

    this.browserWindow.on('unresponsive', () => {
      if (this.isSpec) return
      dialog.showMessageBox(this.browserWindow, {