Skip to content

Commit

Permalink
Es6ify api docs (#21686)
Browse files Browse the repository at this point in the history
* docs: es6ify docs -> var -> const / let

* docs: apply arrow functions throughout all of the docs
  • Loading branch information
Jornn authored and zcbenz committed Jan 13, 2020
1 parent 29b7d80 commit aef9ab1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion docs/api/breaking-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ However, it is recommended to avoid using the `remote` module altogether.
// main
const { ipcMain, webContents } = require('electron')

const getGuestForWebContents = function (webContentsId, contents) {
const getGuestForWebContents = (webContentsId, contents) => {
const guest = webContents.fromId(webContentsId)
if (!guest) {
throw new Error(`Invalid webContentsId: ${webContentsId}`)
Expand Down
10 changes: 5 additions & 5 deletions docs/api/session.md
Original file line number Diff line number Diff line change
Expand Up @@ -519,12 +519,12 @@ A [`Protocol`](protocol.md) object for this session.
const { app, session } = require('electron')
const path = require('path')

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

app.on('ready', async function () {
app.on('ready', async () => {
const netLog = session.fromPartition('some-partition').netLog
netLog.startLogging('/path/to/net-log')
// After some network events
Expand Down
4 changes: 2 additions & 2 deletions docs/api/web-contents.md
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ Injects CSS into the current web page and returns a unique key for the inserted
stylesheet.

```js
contents.on('did-finish-load', function () {
contents.on('did-finish-load', () => {
contents.insertCSS('html, body { background-color: #f00; }')
})
```
Expand All @@ -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)`.

```js
contents.on('did-finish-load', async function () {
contents.on('did-finish-load', async () => {
const key = await contents.insertCSS('html, body { background-color: #f00; }')
contents.removeInsertedCSS(key)
})
Expand Down
2 changes: 1 addition & 1 deletion docs/development/build-system-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ you're currently working on using Mocha's
`.only` to any `describe` or `it` function call:

```js
describe.only('some feature', function () {
describe.only('some feature', () => {
// ... only tests in this block will be run
})
```
Expand Down
26 changes: 13 additions & 13 deletions docs/tutorial/automated-testing-with-a-custom-driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

```js
var childProcess = require('child_process')
var electronPath = require('electron')
const childProcess = require('child_process')
const electronPath = require('electron')

// spawn the process
var env = { /* ... */ }
var stdio = ['inherit', 'inherit', 'inherit', 'ipc']
var appProcess = childProcess.spawn(electronPath, ['./app'], { stdio, env })
let env = { /* ... */ }
let stdio = ['inherit', 'inherit', 'inherit', 'ipc']
let appProcess = childProcess.spawn(electronPath, ['./app'], { stdio, env })

// listen for IPC messages from the app
appProcess.on('message', (msg) => {
Expand Down Expand Up @@ -50,7 +50,7 @@ class TestDriver {
// handle rpc responses
this.process.on('message', (message) => {
// pop the handler
var rpcCall = this.rpcCalls[message.msgId]
let rpcCall = this.rpcCalls[message.msgId]
if (!rpcCall) return
this.rpcCalls[message.msgId] = null
// reject/resolve
Expand All @@ -70,7 +70,7 @@ class TestDriver {
// to use: driver.rpc('method', 1, 2, 3).then(...)
async rpc (cmd, ...args) {
// send rpc request
var msgId = this.rpcCalls.length
let msgId = this.rpcCalls.length
this.process.send({ msgId, cmd, args })
return new Promise((resolve, reject) => this.rpcCalls.push({ resolve, reject }))
}
Expand All @@ -89,13 +89,13 @@ if (process.env.APP_TEST_DRIVER) {
}

async function onMessage ({ msgId, cmd, args }) {
var method = METHODS[cmd]
let method = METHODS[cmd]
if (!method) method = () => new Error('Invalid method: ' + cmd)
try {
var resolve = await method(...args)
let resolve = await method(...args)
process.send({ msgId, resolve })
} catch (err) {
var reject = {
let reject = {
message: err.message,
stack: err.stack,
name: err.name
Expand All @@ -116,10 +116,10 @@ const METHODS = {
Then, in your test suite, you can use your test-driver as follows:

```js
var test = require('ava')
var electronPath = require('electron')
const test = require('ava')
const electronPath = require('electron')

var app = new TestDriver({
let app = new TestDriver({
path: electronPath,
args: ['./app'],
env: {
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/in-app-purchases.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ inAppPurchase.on('transactions-updated', (event, transactions) => {

// Check each transaction.
transactions.forEach(function (transaction) {
var payment = transaction.payment
let payment = transaction.payment

switch (transaction.transactionState) {
case 'purchasing':
Expand Down

0 comments on commit aef9ab1

Please sign in to comment.