1

I'm trying to learn how to use electron with Angular and got confused with syntax I saw from the Electrogram app.

Link: https://github.com/onehungrymind/electrogram

In the app.ts file of electrogram's project, I saw the syntax:

import { remote, ipcRenderer } from 'electron';
...
let {dialog} = remote;

I think it's referring to dialog: Electron.Dialog; in the projects index.d.ts at path typings/globals/github-electron although I really don't know yet how this is happening. (I'm also really new to typescript).

If this was globally declared shouldn't it be at least Electron.CommonElectron.dialog? How can the compiler just know right away what we are referring to by just saying let { dialog }?

Any explanation on this would be greatly appreciated as I really have no idea whats going on.

Jonathan002
  • 7,041
  • 4
  • 23
  • 46
  • 2
    `The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.` https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Object_destructuring – yurzui Jul 14 '17 at 12:15
  • Yes, but it's not like the imports have concatenated with app.ts. All imports have been obj vars. The list of imports is shown below: let filters = require('./../assets/data/filters.json'); import { bootstrap } from '@angular/platform-browser-dynamic'; import { ViewChild, Input, Component, ChangeDetectorRef, ElementRef } from '@angular/core'; import { CanvasService } from './canvasService'; import { remote, ipcRenderer } from 'electron'; import { writeFile } from 'fs'; – Jonathan002 Jul 14 '17 at 12:17
  • This has nothing to do with TypeScript, or Angular, or Electron. It's just plain old JavaScript (ES6). –  Jul 14 '17 at 12:32

1 Answers1

-1

The word you are looking for is destructuring. See https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment

Essentially, pick one property out of an object and create a new variable for it.

let a = { x: 1, y: 2 };
let { x } = a;
console.log(x) // 1
danneth
  • 2,563
  • 1
  • 19
  • 29
  • No. That's not the word you are looking for. –  Jul 14 '17 at 12:33
  • Thanks for this! I've been looking around the typescript gitbook thinking it was some sort of special way to load a typings module haha. – Jonathan002 Jul 14 '17 at 12:38