Es6ify api docs (#21686)

* docs: es6ify docs -> var -> const / let

* docs: apply arrow functions throughout all of the docs
This commit is contained in:
Jorn 2020-01-13 02:29:46 +01:00 committed by Cheng Zhao
parent 29b7d80eb5
commit aef9ab1bb7
6 changed files with 23 additions and 23 deletions

View file

@ -116,7 +116,7 @@ However, it is recommended to avoid using the `remote` module altogether.
// main // main
const { ipcMain, webContents } = require('electron') const { ipcMain, webContents } = require('electron')
const getGuestForWebContents = function (webContentsId, contents) { const getGuestForWebContents = (webContentsId, contents) => {
const guest = webContents.fromId(webContentsId) const guest = webContents.fromId(webContentsId)
if (!guest) { if (!guest) {
throw new Error(`Invalid webContentsId: ${webContentsId}`) throw new Error(`Invalid webContentsId: ${webContentsId}`)

View file

@ -519,12 +519,12 @@ A [`Protocol`](protocol.md) object for this session.
const { app, session } = require('electron') const { app, session } = require('electron')
const path = require('path') const path = require('path')
app.on('ready', function () { app.on('ready', () => {
const protocol = session.fromPartition('some-partition').protocol const protocol = session.fromPartition('some-partition').protocol
protocol.registerFileProtocol('atom', function (request, callback) { protocol.registerFileProtocol('atom', (request, callback) => {
var url = request.url.substr(7) let url = request.url.substr(7)
callback({ path: path.normalize(`${__dirname}/${url}`) }) callback({ path: path.normalize(`${__dirname}/${url}`) })
}, function (error) { }, (error) => {
if (error) console.error('Failed to register protocol') if (error) console.error('Failed to register protocol')
}) })
}) })
@ -537,7 +537,7 @@ A [`NetLog`](net-log.md) object for this session.
```javascript ```javascript
const { app, session } = require('electron') const { app, session } = require('electron')
app.on('ready', async function () { app.on('ready', async () => {
const netLog = session.fromPartition('some-partition').netLog const netLog = session.fromPartition('some-partition').netLog
netLog.startLogging('/path/to/net-log') netLog.startLogging('/path/to/net-log')
// After some network events // After some network events

View file

@ -987,7 +987,7 @@ Injects CSS into the current web page and returns a unique key for the inserted
stylesheet. stylesheet.
```js ```js
contents.on('did-finish-load', function () { contents.on('did-finish-load', () => {
contents.insertCSS('html, body { background-color: #f00; }') contents.insertCSS('html, body { background-color: #f00; }')
}) })
``` ```
@ -1002,7 +1002,7 @@ Removes the inserted CSS from the current web page. The stylesheet is identified
by its key, which is returned from `contents.insertCSS(css)`. by its key, which is returned from `contents.insertCSS(css)`.
```js ```js
contents.on('did-finish-load', async function () { contents.on('did-finish-load', async () => {
const key = await contents.insertCSS('html, body { background-color: #f00; }') const key = await contents.insertCSS('html, body { background-color: #f00; }')
contents.removeInsertedCSS(key) contents.removeInsertedCSS(key)
}) })

View file

@ -57,7 +57,7 @@ you're currently working on using Mocha's
`.only` to any `describe` or `it` function call: `.only` to any `describe` or `it` function call:
```js ```js
describe.only('some feature', function () { describe.only('some feature', () => {
// ... only tests in this block will be run // ... only tests in this block will be run
}) })
``` ```

View file

@ -5,13 +5,13 @@ To write automated tests for your Electron app, you will need a way to "drive" y
To create a custom driver, we'll use Node.js' [child_process](https://nodejs.org/api/child_process.html) API. The test suite will spawn the Electron process, then establish a simple messaging protocol: To create a custom driver, we'll use Node.js' [child_process](https://nodejs.org/api/child_process.html) API. The test suite will spawn the Electron process, then establish a simple messaging protocol:
```js ```js
var childProcess = require('child_process') const childProcess = require('child_process')
var electronPath = require('electron') const electronPath = require('electron')
// spawn the process // spawn the process
var env = { /* ... */ } let env = { /* ... */ }
var stdio = ['inherit', 'inherit', 'inherit', 'ipc'] let stdio = ['inherit', 'inherit', 'inherit', 'ipc']
var appProcess = childProcess.spawn(electronPath, ['./app'], { stdio, env }) let appProcess = childProcess.spawn(electronPath, ['./app'], { stdio, env })
// listen for IPC messages from the app // listen for IPC messages from the app
appProcess.on('message', (msg) => { appProcess.on('message', (msg) => {
@ -50,7 +50,7 @@ class TestDriver {
// handle rpc responses // handle rpc responses
this.process.on('message', (message) => { this.process.on('message', (message) => {
// pop the handler // pop the handler
var rpcCall = this.rpcCalls[message.msgId] let rpcCall = this.rpcCalls[message.msgId]
if (!rpcCall) return if (!rpcCall) return
this.rpcCalls[message.msgId] = null this.rpcCalls[message.msgId] = null
// reject/resolve // reject/resolve
@ -70,7 +70,7 @@ class TestDriver {
// to use: driver.rpc('method', 1, 2, 3).then(...) // to use: driver.rpc('method', 1, 2, 3).then(...)
async rpc (cmd, ...args) { async rpc (cmd, ...args) {
// send rpc request // send rpc request
var msgId = this.rpcCalls.length let msgId = this.rpcCalls.length
this.process.send({ msgId, cmd, args }) this.process.send({ msgId, cmd, args })
return new Promise((resolve, reject) => this.rpcCalls.push({ resolve, reject })) return new Promise((resolve, reject) => this.rpcCalls.push({ resolve, reject }))
} }
@ -89,13 +89,13 @@ if (process.env.APP_TEST_DRIVER) {
} }
async function onMessage ({ msgId, cmd, args }) { async function onMessage ({ msgId, cmd, args }) {
var method = METHODS[cmd] let method = METHODS[cmd]
if (!method) method = () => new Error('Invalid method: ' + cmd) if (!method) method = () => new Error('Invalid method: ' + cmd)
try { try {
var resolve = await method(...args) let resolve = await method(...args)
process.send({ msgId, resolve }) process.send({ msgId, resolve })
} catch (err) { } catch (err) {
var reject = { let reject = {
message: err.message, message: err.message,
stack: err.stack, stack: err.stack,
name: err.name name: err.name
@ -116,10 +116,10 @@ const METHODS = {
Then, in your test suite, you can use your test-driver as follows: Then, in your test suite, you can use your test-driver as follows:
```js ```js
var test = require('ava') const test = require('ava')
var electronPath = require('electron') const electronPath = require('electron')
var app = new TestDriver({ let app = new TestDriver({
path: electronPath, path: electronPath,
args: ['./app'], args: ['./app'],
env: { env: {

View file

@ -37,7 +37,7 @@ inAppPurchase.on('transactions-updated', (event, transactions) => {
// Check each transaction. // Check each transaction.
transactions.forEach(function (transaction) { transactions.forEach(function (transaction) {
var payment = transaction.payment let payment = transaction.payment
switch (transaction.transactionState) { switch (transaction.transactionState) {
case 'purchasing': case 'purchasing':