refactor: convert browser window state fns to props (#18618)

This commit is contained in:
Shelley Vohr 2019-06-04 22:44:16 -07:00 committed by GitHub
parent 164cc43440
commit a0b1f4fe0b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 260 additions and 60 deletions

View file

@ -57,17 +57,18 @@ const deprecate: ElectronInternal.DeprecationUtil = {
},
// deprecate a getter/setter function pair in favor of a property
fnToProperty: (module: any, prop: string, getter: string, setter: string) => {
const withWarnOnce = (obj: any, key: any, oldName: string, newName: string) => {
fnToProperty: (prototype: any, prop: string, getter: string, setter: string) => {
const withWarnOnce = function (obj: any, key: any, oldName: string, newName: string) {
const warn = warnOnce(oldName, newName)
return (...args: any) => {
const method = obj[key]
return function (this: any, ...args: any) {
warn()
return obj[key](...args)
return method.apply(this, args)
}
}
module[getter.substr(1)] = withWarnOnce(module, getter, `${getter.substr(1)} function`, `${prop} property`)
module[setter.substr(1)] = withWarnOnce(module, setter, `${setter.substr(1)} function`, `${prop} property`)
prototype[getter.substr(1)] = withWarnOnce(prototype, getter, `${getter.substr(1)} function`, `${prop} property`)
prototype[setter.substr(1)] = withWarnOnce(prototype, setter, `${setter.substr(1)} function`, `${prop} property`)
},
// remove a property with no replacement