2015-11-09 10:09:22 +00:00
|
|
|
# Deprecate a method.
|
|
|
|
deprecate = (oldName, newName, fn) ->
|
|
|
|
warned = false
|
|
|
|
->
|
|
|
|
unless warned or process.noDeprecation
|
|
|
|
warned = true
|
|
|
|
deprecate.warn oldName, newName
|
|
|
|
fn.apply this, arguments
|
|
|
|
|
|
|
|
# The method is renamed.
|
|
|
|
deprecate.rename = (object, oldName, newName) ->
|
|
|
|
warned = false
|
|
|
|
newMethod = ->
|
|
|
|
unless warned or process.noDeprecation
|
|
|
|
warned = true
|
|
|
|
deprecate.warn oldName, newName
|
|
|
|
this[newName].apply this, arguments
|
|
|
|
if typeof object is 'function'
|
|
|
|
object.prototype[oldName] = newMethod
|
|
|
|
else
|
|
|
|
object[oldName] = newMethod
|
|
|
|
|
|
|
|
# Forward the method to member.
|
|
|
|
deprecate.member = (object, method, member) ->
|
|
|
|
warned = false
|
|
|
|
object.prototype[method] = ->
|
|
|
|
unless warned or process.noDeprecation
|
|
|
|
warned = true
|
|
|
|
deprecate.warn method, "#{member}.#{method}"
|
|
|
|
this[member][method].apply this[member], arguments
|
|
|
|
|
|
|
|
# Deprecate a property.
|
|
|
|
deprecate.property = (object, property, method) ->
|
|
|
|
Object.defineProperty object, property,
|
|
|
|
get: ->
|
|
|
|
warned = false
|
|
|
|
unless warned or process.noDeprecation
|
|
|
|
warned = true
|
|
|
|
deprecate.warn "#{property} property", "#{method} method"
|
|
|
|
this[method]()
|
|
|
|
|
|
|
|
# Deprecate an event.
|
|
|
|
deprecate.event = (emitter, oldName, newName, fn) ->
|
|
|
|
warned = false
|
2015-11-13 08:41:33 +00:00
|
|
|
emitter.on newName, (args...) ->
|
2015-11-09 10:09:22 +00:00
|
|
|
if @listenerCount(oldName) > 0 # there is listeners for old API.
|
|
|
|
unless warned or process.noDeprecation
|
|
|
|
warned = true
|
|
|
|
deprecate.warn "'#{oldName}' event", "'#{newName}' event"
|
2015-11-13 08:41:33 +00:00
|
|
|
if fn?
|
|
|
|
fn.apply this, arguments
|
|
|
|
else
|
|
|
|
@emit oldName, args...
|
2015-11-09 10:09:22 +00:00
|
|
|
|
2015-12-16 00:44:38 +00:00
|
|
|
# Print deprecation warning.
|
2015-11-09 10:09:22 +00:00
|
|
|
deprecate.warn = (oldName, newName) ->
|
2015-12-16 00:46:53 +00:00
|
|
|
deprecate.log "#{oldName} is deprecated. Use #{newName} instead."
|
2015-12-16 00:22:31 +00:00
|
|
|
|
2015-12-16 00:47:19 +00:00
|
|
|
# Print deprecation message.
|
2015-12-16 00:22:31 +00:00
|
|
|
deprecate.log = (message) ->
|
2015-11-09 10:09:22 +00:00
|
|
|
if process.throwDeprecation
|
|
|
|
throw new Error(message)
|
|
|
|
else if process.traceDeprecation
|
|
|
|
console.trace message
|
|
|
|
else
|
|
|
|
console.warn "(electron) #{message}"
|
|
|
|
|
|
|
|
module.exports = deprecate
|