🎨 Use const and for/of loops
This commit is contained in:
parent
3bcb411e28
commit
ce1a9740f6
1 changed files with 12 additions and 13 deletions
|
@ -57,12 +57,12 @@ var getNextInstanceId = function () {
|
||||||
|
|
||||||
// Create a new guest instance.
|
// Create a new guest instance.
|
||||||
var createGuest = function (embedder, params) {
|
var createGuest = function (embedder, params) {
|
||||||
var destroy, destroyEvents, event, fn, guest, i, id, j, len, len1, listeners
|
|
||||||
if (webViewManager == null) {
|
if (webViewManager == null) {
|
||||||
webViewManager = process.atomBinding('web_view_manager')
|
webViewManager = process.atomBinding('web_view_manager')
|
||||||
}
|
}
|
||||||
id = getNextInstanceId(embedder)
|
|
||||||
guest = webContents.create({
|
const id = getNextInstanceId(embedder)
|
||||||
|
const guest = webContents.create({
|
||||||
isGuest: true,
|
isGuest: true,
|
||||||
partition: params.partition,
|
partition: params.partition,
|
||||||
embedder: embedder
|
embedder: embedder
|
||||||
|
@ -73,20 +73,19 @@ var createGuest = function (embedder, params) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destroy guest when the embedder is gone or navigated.
|
// Destroy guest when the embedder is gone or navigated.
|
||||||
destroyEvents = ['will-destroy', 'crashed', 'did-navigate']
|
const destroyEvents = ['will-destroy', 'crashed', 'did-navigate']
|
||||||
destroy = function () {
|
const destroy = function () {
|
||||||
if (guestInstances[id] != null) {
|
if (guestInstances[id] != null) {
|
||||||
return destroyGuest(embedder, id)
|
destroyGuest(embedder, id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = 0, len = destroyEvents.length; i < len; i++) {
|
for (const event of destroyEvents) {
|
||||||
event = destroyEvents[i]
|
|
||||||
embedder.once(event, destroy)
|
embedder.once(event, destroy)
|
||||||
|
|
||||||
// Users might also listen to the crashed event, so We must ensure the guest
|
// Users might also listen to the crashed event, so We must ensure the guest
|
||||||
// is destroyed before users' listener gets called. It is done by moving our
|
// is destroyed before users' listener gets called. It is done by moving our
|
||||||
// listener to the first one in queue.
|
// listener to the first one in queue.
|
||||||
listeners = embedder._events[event]
|
const listeners = embedder._events[event]
|
||||||
if (Array.isArray(listeners)) {
|
if (Array.isArray(listeners)) {
|
||||||
moveLastToFirst(listeners)
|
moveLastToFirst(listeners)
|
||||||
}
|
}
|
||||||
|
@ -132,13 +131,12 @@ var createGuest = function (embedder, params) {
|
||||||
})
|
})
|
||||||
|
|
||||||
// Dispatch events to embedder.
|
// Dispatch events to embedder.
|
||||||
fn = function (event) {
|
const fn = function (event) {
|
||||||
return guest.on(event, function (_, ...args) {
|
guest.on(event, function (_, ...args) {
|
||||||
embedder.send.apply(embedder, ['ELECTRON_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-' + guest.viewInstanceId, event].concat(args))
|
embedder.send.apply(embedder, ['ELECTRON_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-' + guest.viewInstanceId, event].concat(args))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
for (j = 0, len1 = supportedWebViewEvents.length; j < len1; j++) {
|
for (const event of supportedWebViewEvents) {
|
||||||
event = supportedWebViewEvents[j]
|
|
||||||
fn(event)
|
fn(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,6 +149,7 @@ var createGuest = function (embedder, params) {
|
||||||
guest.on('size-changed', function (_, ...args) {
|
guest.on('size-changed', function (_, ...args) {
|
||||||
embedder.send.apply(embedder, ['ELECTRON_GUEST_VIEW_INTERNAL_SIZE_CHANGED-' + guest.viewInstanceId].concat(args))
|
embedder.send.apply(embedder, ['ELECTRON_GUEST_VIEW_INTERNAL_SIZE_CHANGED-' + guest.viewInstanceId].concat(args))
|
||||||
})
|
})
|
||||||
|
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue