From c5913c31493dd36b1455c5f1c9a28d65f67c5c72 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 12 Nov 2015 22:24:11 +0800 Subject: [PATCH] docs: Add notes on old APIs --- docs/api/synopsis.md | 63 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/docs/api/synopsis.md b/docs/api/synopsis.md index 8df1ca9..f6c161b 100644 --- a/docs/api/synopsis.md +++ b/docs/api/synopsis.md @@ -9,12 +9,10 @@ desktop applications. Some modules are only available in the main process, some are only available in the renderer process (web page), and some can be used in both processes. -The basic rule is: if a module is -[GUI](https://en.wikipedia.org/wiki/Graphical_user_interface) or low-level -system related, then it should be only available in the main process. You need -to be familiar with the concept of -[main process vs. renderer process](../tutorial/quick-start.md#the-main-process) -scripts to be able to use those modules. +The basic rule is: if a module is [GUI][gui] or low-level system related, then +it should be only available in the main process. You need to be familiar with +the concept of [main process vs. renderer process][mai-process] scripts to be +able to use those modules. The main process script is just like a normal Node.js script: @@ -31,19 +29,56 @@ app.on('ready', function() { }); ``` -The renderer process is no different than a normal web page, except for the extra -ability to use node modules: +The renderer process is no different than a normal web page, except for the +extra ability to use node modules: ```html - - - + + + ``` To run your app, read [Run your app](../tutorial/quick-start.md#run-your-app). + +## Destructuring assignment + +If you are using CoffeeScript or Babel, you can also use +[destructuring assignment][desctructuring-assignment] to make it easier to use +built-in modules: + +```javascript +const {app, BrowserWindow} = require('electron') +``` + +However if you are using plain JavaScript, you have to wait until Chrome fully +supports ES6. + +## Disable old styles of using built-in modules + +Before v0.35.0, all built-in modules have to be used in the form of +`require('module-name')`, though it has [many disadvantages][issue-387], we are +still supporting it for compatibility with old apps. + +To disable the old styles completely, you can set the +`ELECTRON_HIDE_INTERNAL_MODULES` environment variable: + +```javascript +process.env.ELECTRON_HIDE_INTERNAL_MODULES = 'true' +``` + +Or call the `hideInternalModules` API: + +```javascript +require('electron').hideInternalModules() +``` + +[gui]: https://en.wikipedia.org/wiki/Graphical_user_interface +[main-process]: ../tutorial/quick-start.md#the-main-process +[desctructuring-assignment]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment +[issue-387]: https://github.com/atom/electron/issues/387 -- 2.7.4