chore: add guard for console.debug

This commit is contained in:
07akioni 2020-06-25 16:02:31 +08:00
parent 336743598e
commit 76153e3715
9 changed files with 122 additions and 42 deletions

View File

@ -6,10 +6,14 @@ function lazyHandler (handler) {
let called = false
return function (e) {
if (called) {
console.debug('[clickoutside] called')
if (process.env.NODE_ENV !== 'production') {
console.debug('[clickoutside] called')
}
handler(e)
} else {
console.debug('[clickoutside] lazy called')
if (process.env.NODE_ENV !== 'production') {
console.debug('[clickoutside] lazy called')
}
called = true
}
}
@ -18,7 +22,9 @@ function lazyHandler (handler) {
const clickoutside = {
bind (el, bindings) {
// console.debug('[clickoutside]: bind', el)
console.debug('[clickoutside]: bind $el')
if (process.env.NODE_ENV !== 'production') {
console.debug('[clickoutside]: bind $el')
}
if (typeof bindings.value === 'function') {
el[ctx] = {
handler: bindings.modifiers.lazy ? lazyHandler(bindings.value) : bindings.value
@ -27,7 +33,9 @@ const clickoutside = {
}
},
inserted (el, bindings) {
console.debug('[clickoutside]: inserted')
if (process.env.NODE_ENV !== 'production') {
console.debug('[clickoutside]: inserted')
}
// if (typeof bindings.value === 'function') {
// el[ctx] = {
// handler: bindings.modifiers.lazy ? lazyHandler(bindings.value) : bindings.value
@ -44,7 +52,9 @@ const clickoutside = {
// }
// },
componentUpdated (el, bindings) {
console.debug('[clickoutside]: componentUpdated')
if (process.env.NODE_ENV !== 'production') {
console.debug('[clickoutside]: componentUpdated')
}
if (typeof bindings.value === 'function') {
if (el[ctx] && el[ctx].handler) {
if (el[ctx].handler !== bindings.value) {
@ -63,7 +73,9 @@ const clickoutside = {
}
},
unbind (el) {
console.debug('[clickoutside]: unbind')
if (process.env.NODE_ENV !== 'production') {
console.debug('[clickoutside]: unbind')
}
el[ctx] && clickoutsideDelegate.unregisterHandler(el[ctx].handler)
}
}

View File

@ -6,10 +6,14 @@ function lazyHandler (handler) {
let called = false
return function (e) {
if (called) {
console.debug('[mousemoveoutside] called')
if (process.env.NODE_ENV !== 'production') {
console.debug('[mousemoveoutside] called')
}
handler(e)
} else {
console.debug('[mousemoveoutside] lazy called')
if (process.env.NODE_ENV !== 'production') {
console.debug('[mousemoveoutside] lazy called')
}
called = true
}
}
@ -18,7 +22,9 @@ function lazyHandler (handler) {
const mousemoveoutside = {
bind (el, bindings) {
// console.debug('[mousemoveoutside]: bind', el)
console.debug('[mousemoveoutside]: bind $el')
if (process.env.NODE_ENV !== 'production') {
console.debug('[mousemoveoutside]: bind $el')
}
if (typeof bindings.value === 'function') {
el[ctx] = {
handler: bindings.modifiers.lazy ? lazyHandler(bindings.value) : bindings.value
@ -27,7 +33,9 @@ const mousemoveoutside = {
}
},
inserted () {
console.debug('[mousemoveoutside]: inserted')
if (process.env.NODE_ENV !== 'production') {
console.debug('[mousemoveoutside]: inserted')
}
},
// update (el, bindings) {
// console.debug('[mousemoveoutside]: update')
@ -38,7 +46,9 @@ const mousemoveoutside = {
// }
// },
componentUpdated (el, bindings) {
console.debug('[mousemoveoutside]: componentUpdated')
if (process.env.NODE_ENV !== 'production') {
console.debug('[mousemoveoutside]: componentUpdated')
}
if (typeof bindings.value === 'function') {
if (el[ctx] && el[ctx].handler) {
if (el[ctx].handler !== bindings.value) {
@ -57,7 +67,9 @@ const mousemoveoutside = {
}
},
unbind (el) {
console.debug('[mousemoveoutside]: unbind')
if (process.env.NODE_ENV !== 'production') {
console.debug('[mousemoveoutside]: unbind')
}
moveoutsideDelegate.unregisterHandler(el[ctx].handler)
}
}

View File

@ -24,7 +24,9 @@ export default {
watch: {
active (value) {
if (!this.syntheticDetachable && !this.zindexable) return
console.debug('[zindexable.watch.active]:', value)
if (process.env.NODE_ENV !== 'production') {
console.debug('[zindexable.watch.active]:', value)
}
if (value) {
this._initZindexable()
zIndexManager.setNewZIndex(this._getZindexableContent(), this.zIndex)

View File

@ -1,6 +1,8 @@
class ClickOutsideDelegate {
constructor () {
console.debug('[ClickOutsideDelegate]: Ctor called')
if (process.env.NODE_ENV !== 'production') {
console.debug('[ClickOutsideDelegate]: Ctor called')
}
this.handlers = new Map()
this.handlerCount = 0
this.mouseDownTarget = null
@ -38,18 +40,28 @@ class ClickOutsideDelegate {
}
}
unregisterHandler (handler) {
console.debug('[ClickOutsideDelegate]: unregisterHandler')
if (process.env.NODE_ENV !== 'production') {
console.debug('[ClickOutsideDelegate]: unregisterHandler')
}
const h = this.handlers.get(handler)
if (h) {
console.debug('[ClickOutsideDelegate.unregisterHandler]: handler found')
if (process.env.NODE_ENV !== 'production') {
console.debug('[ClickOutsideDelegate.unregisterHandler]: handler found')
}
this.handlers.delete(handler)
--this.handlerCount
console.debug('[ClickOutsideDelegate.unregisterHandler]: handler unregistered')
if (process.env.NODE_ENV !== 'production') {
console.debug('[ClickOutsideDelegate.unregisterHandler]: handler unregistered')
}
} else {
console.debug('[ClickOutsideDelegate.unregisterHandler]: handler not found')
if (process.env.NODE_ENV !== 'production') {
console.debug('[ClickOutsideDelegate.unregisterHandler]: handler not found')
}
}
if (!this.handlerCount) {
console.debug('[ClickOutsideDelegate]: remove handler from window')
if (process.env.NODE_ENV !== 'production') {
console.debug('[ClickOutsideDelegate]: remove handler from window')
}
window.removeEventListener('mouseup', this.handleMouseUpOutside)
window.removeEventListener('mousedown', this.handleMouseDown)
this.mouseDownTarget = null
@ -67,7 +79,9 @@ class ClickOutsideDelegate {
throw new Error('[ClickOutsideDelegate.registerHandler]: don\'t register duplicate event handler, if you want to do it, unregister this handler and reregister it.')
}
if (!this.handlerCount) {
console.debug('[ClickOutsideDelegate]: add handler to window')
if (process.env.NODE_ENV !== 'production') {
console.debug('[ClickOutsideDelegate]: add handler to window')
}
window.addEventListener('mouseup', this.handleMouseUpOutside)
window.addEventListener('mousedown', this.handleMouseDown)
}

View File

@ -1,6 +1,8 @@
class MoveOutsideDelegate {
constructor () {
console.debug('[MoveOutsideDelegate]: Ctor called')
if (process.env.NODE_ENV !== 'production') {
console.debug('[MoveOutsideDelegate]: Ctor called')
}
this.handlers = new Map()
this.handlerCount = 0
this.handleMoveOutside = this.handleMoveOutside.bind(this)
@ -33,14 +35,18 @@ class MoveOutsideDelegate {
}
}
unregisterHandler (handler) {
console.debug('[MoveOutsideDelegate]: unregisterHandler')
if (process.env.NODE_ENV !== 'production') {
console.debug('[MoveOutsideDelegate]: unregisterHandler')
}
const h = this.handlers.get(handler)
if (h) {
this.handlers.delete(handler)
--this.handlerCount
}
if (!this.handlerCount) {
console.debug('[MoveOutsideDelegate]: remove handler from window')
if (process.env.NODE_ENV !== 'production') {
console.debug('[MoveOutsideDelegate]: remove handler from window')
}
window.removeEventListener('mousemove', this.handleMoveOutside, true)
this.handlers = new Map()
}
@ -57,7 +63,9 @@ class MoveOutsideDelegate {
return
}
if (!this.handlerCount) {
console.debug('[MoveOutsideDelegate]: add handler to window')
if (process.env.NODE_ENV !== 'production') {
console.debug('[MoveOutsideDelegate]: add handler to window')
}
window.addEventListener('mousemove', this.handleMoveOutside, true)
}
++this.handlerCount

View File

@ -1,6 +1,8 @@
class MutationObserverDelegate {
constructor () {
console.debug('[MutationObserverDelegate]: Ctor called')
if (process.env.NODE_ENV !== 'production') {
console.debug('[MutationObserverDelegate]: Ctor called')
}
this.handlers = new Map()
this.observers = new Map()
this.handleMutation = this.handleMutation.bind(this)

View File

@ -1,6 +1,8 @@
class ResizeDelegate {
constructor () {
console.debug('[ResizeDelegate]: Ctor called')
if (process.env.NODE_ENV !== 'production') {
console.debug('[ResizeDelegate]: Ctor called')
}
this.handlers = []
this.handleResize = this.handleResize.bind(this)
}
@ -23,13 +25,17 @@ class ResizeDelegate {
}
}
if (!handlers.length) {
console.debug('[ResizeDelegate]: remove resize handler from window')
if (process.env.NODE_ENV !== 'production') {
console.debug('[ResizeDelegate]: remove resize handler from window')
}
window.removeEventListener('resize', this.handleResize, true)
}
}
registerHandler (handler) {
if (!this.handlers.length) {
console.debug('[ResizeDelegate]: add resize handler to window')
if (process.env.NODE_ENV !== 'production') {
console.debug('[ResizeDelegate]: add resize handler to window')
}
window.addEventListener('resize', this.handleResize, true)
}
this.handlers.push(handler)

View File

@ -1,6 +1,8 @@
class ScrollDelegate {
constructor () {
console.debug('[ScrollDelegate]: Ctor called')
if (process.env.NODE_ENV !== 'production') {
console.debug('[ScrollDelegate]: Ctor called')
}
this.handlers = new Map()
this.handlerCount = 0
this.handleScroll = this.handleScroll.bind(this)
@ -28,14 +30,18 @@ class ScrollDelegate {
}
}
if (!this.handlerCount) {
console.debug('[ScrollDelegate]: remove handler from window')
if (process.env.NODE_ENV !== 'production') {
console.debug('[ScrollDelegate]: remove handler from window')
}
window.removeEventListener('scroll', this.handleScroll, true)
this.handlers = new Map()
}
}
registerHandler (el, handler) {
if (!this.handlerCount) {
console.debug('[ScrollDelegate]: add handler to window')
if (process.env.NODE_ENV !== 'production') {
console.debug('[ScrollDelegate]: add handler to window')
}
window.addEventListener('scroll', this.handleScroll, true)
}
++this.handlerCount

View File

@ -4,7 +4,9 @@
class ZIndexManager {
constructor () {
console.debug('[ZIndexManager]: Ctor called')
if (process.env.NODE_ENV !== 'production') {
console.debug('[ZIndexManager]: Ctor called')
}
this.elementZIndex = new Map()
this.nextZIndex = 2000
}
@ -12,12 +14,18 @@ class ZIndexManager {
return this.elementZIndex.size
}
registerElement (el, zIndex) {
console.debug('[ZIndexManager.registerElement]: called', el)
if (process.env.NODE_ENV !== 'production') {
console.debug('[ZIndexManager.registerElement]: called', el)
}
if (this.elementZIndex.has(el)) {
console.debug('[ZIndexManager.registerElement]: do not register duplicate element')
if (process.env.NODE_ENV !== 'production') {
console.debug('[ZIndexManager.registerElement]: do not register duplicate element')
}
} else {
// console.debug('[ZIndexManager.registerElement]: successfully register', el)
console.debug('[ZIndexManager.registerElement]: successfully register $el')
if (process.env.NODE_ENV !== 'production') {
// console.debug('[ZIndexManager.registerElement]: successfully register', el)
console.debug('[ZIndexManager.registerElement]: successfully register $el')
}
el.style.zIndex = this.nextZIndex
if (zIndex !== undefined) {
el.style.zIndex = zIndex
@ -30,10 +38,14 @@ class ZIndexManager {
this.afterManipulation()
}
setNewZIndex (el, zIndex) {
console.debug('[ZIndexManager.setNewZIndex]: called')
if (process.env.NODE_ENV !== 'production') {
console.debug('[ZIndexManager.setNewZIndex]: called')
}
if (this.elementZIndex.has(el)) {
// console.debug('[ZIndexManager.setNewZIndex]: successfully set z-index on', el, `(z-index: ${this.nextZIndex})`)
console.debug('[ZIndexManager.setNewZIndex]: successfully set z-index on $el' + `(z-index: ${this.nextZIndex})`)
if (process.env.NODE_ENV !== 'production') {
// console.debug('[ZIndexManager.setNewZIndex]: successfully set z-index on', el, `(z-index: ${this.nextZIndex})`)
console.debug('[ZIndexManager.setNewZIndex]: successfully set z-index on $el' + `(z-index: ${this.nextZIndex})`)
}
if (zIndex !== undefined) {
el.style.zIndex = zIndex
this.elementZIndex.set(el, null)
@ -45,14 +57,20 @@ class ZIndexManager {
this.elementZIndex.set(el, this.nextZIndex)
this.nextZIndex++
} else {
console.debug('[ZIndexManager.setNewZIndex]: element not found, please register it first')
if (process.env.NODE_ENV !== 'production') {
console.debug('[ZIndexManager.setNewZIndex]: element not found, please register it first')
}
}
this.afterManipulation()
}
unregisterElement (el) {
console.debug('[ZIndexManager.unregisterElement]: called')
if (process.env.NODE_ENV !== 'production') {
console.debug('[ZIndexManager.unregisterElement]: called')
}
if (this.elementZIndex.has(el)) {
console.debug('[ZIndexManager.unregisterElement]: successfully delete $el') //, el)
if (process.env.NODE_ENV !== 'production') {
console.debug('[ZIndexManager.unregisterElement]: successfully delete $el') //, el)
}
this.elementZIndex.delete(el)
} else {
console.error(