From 46af3cefec37e13fa03d4b52c155fcb555dcbf40 Mon Sep 17 00:00:00 2001 From: Bret Comnes Date: Mon, 13 Mar 2017 15:42:26 -0700 Subject: [PATCH 1/6] Clarify remote require of relative modules The docs for the `remote.require(module)` method were a little too terse for me to understand the behavior of relative module loading for `remote.require` and I had to run an experiment to understand the behavior (e.g. is the relative path relative to caller of `remote.require` or relative to some other path in the project related to the main process?). I think this is correct but someone please double check my understanding. Adding an example and additional explanation should help clarify this. Feel free to edit the copy as needed. --- docs/api/remote.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/api/remote.md b/docs/api/remote.md index 0bed3ad9b511..7f1c7f09292c 100644 --- a/docs/api/remote.md +++ b/docs/api/remote.md @@ -140,7 +140,26 @@ The `remote` module has the following methods: * `module` String -Returns `any` - The object returned by `require(module)` in the main process. +Returns `any` - The object returned by `require(module)` in the main process. Modules specified by their relative path will resolve relative to the entrypoint of the main process. + +e.g. + +```js +// main process: main/index.js +const { app, ipcMain } = require('electron') +app.on('ready', () => { +//... +``` + +```js +// some relative module: main/foo.js +module.exports = 'bar' +``` + +```js +// renderer process: renderer/index.js +const foo = require('electron').remote.require('./foo') // bar +``` ### `remote.getCurrentWindow()` From f82590b9ab0288409d817e948332a3ab122d4eb3 Mon Sep 17 00:00:00 2001 From: Bret Comnes Date: Mon, 13 Mar 2017 15:48:42 -0700 Subject: [PATCH 2/6] Wrap at 80 --- docs/api/remote.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/api/remote.md b/docs/api/remote.md index 7f1c7f09292c..ccbfbf3fb14f 100644 --- a/docs/api/remote.md +++ b/docs/api/remote.md @@ -140,7 +140,9 @@ The `remote` module has the following methods: * `module` String -Returns `any` - The object returned by `require(module)` in the main process. Modules specified by their relative path will resolve relative to the entrypoint of the main process. +Returns `any` - The object returned by `require(module)` in the main process. +Modules specified by their relative path will resolve relative to the entrypoint +of the main process. e.g. From 2276357f723ada06b31c9595e7bd76a3898e7562 Mon Sep 17 00:00:00 2001 From: Bret Comnes Date: Mon, 13 Mar 2017 17:18:23 -0700 Subject: [PATCH 3/6] update with a tree --- docs/api/remote.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/api/remote.md b/docs/api/remote.md index ccbfbf3fb14f..36b38b835408 100644 --- a/docs/api/remote.md +++ b/docs/api/remote.md @@ -146,11 +146,24 @@ of the main process. e.g. +``` +project/ +├── main +│   ├── foo.js +│   └── index.js +├── package.json +└── renderer + └── index.js +``` + ```js // main process: main/index.js -const { app, ipcMain } = require('electron') +const { app } = require('electron') app.on('ready', () => { -//... + +// ... + +}) ``` ```js From 85c48a23368317bc134c938876d5515abab17349 Mon Sep 17 00:00:00 2001 From: Bret Comnes Date: Mon, 13 Mar 2017 17:20:11 -0700 Subject: [PATCH 4/6] make main process example shorter --- docs/api/remote.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/docs/api/remote.md b/docs/api/remote.md index 36b38b835408..4da19daaa34f 100644 --- a/docs/api/remote.md +++ b/docs/api/remote.md @@ -159,11 +159,7 @@ project/ ```js // main process: main/index.js const { app } = require('electron') -app.on('ready', () => { - -// ... - -}) +app.on('ready', () => {/* ... */}) ``` ```js From b67c81226c05856b09cef9b5066a0d74e23ff424 Mon Sep 17 00:00:00 2001 From: Bret Comnes Date: Tue, 14 Mar 2017 10:48:44 -0700 Subject: [PATCH 5/6] fix linting --- docs/api/remote.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/remote.md b/docs/api/remote.md index 4da19daaa34f..2db8d17c9992 100644 --- a/docs/api/remote.md +++ b/docs/api/remote.md @@ -159,7 +159,7 @@ project/ ```js // main process: main/index.js const { app } = require('electron') -app.on('ready', () => {/* ... */}) +app.on('ready', () => { /* ... */ }) ``` ```js From 55bf2239dfa332197abd54874ddfb6a55c43119e Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 30 Mar 2017 11:58:09 -0700 Subject: [PATCH 6/6] Remove spaces around brackets --- docs/api/remote.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/remote.md b/docs/api/remote.md index 2db8d17c9992..2abb2a843110 100644 --- a/docs/api/remote.md +++ b/docs/api/remote.md @@ -158,7 +158,7 @@ project/ ```js // main process: main/index.js -const { app } = require('electron') +const {app} = require('electron') app.on('ready', () => { /* ... */ }) ```