Browse Source

added colored debug msg + fixed double event sometimes emited

Skylsmoi 6 years ago
parent
commit
fc0a556aa0
1 changed files with 11 additions and 2 deletions
  1. 11 2
      src/container/Thread.jsx

+ 11 - 2
src/container/Thread.jsx View File

39
   customEventReducer = ({ detail: { type, data } }) => { // action: { type: '', data: {} }
39
   customEventReducer = ({ detail: { type, data } }) => { // action: { type: '', data: {} }
40
     switch (type) {
40
     switch (type) {
41
       case 'thread_showApp':
41
       case 'thread_showApp':
42
+        console.log('%c<Thread> Custom event', 'color: #28a745', type, data)
42
         this.setState({isVisible: true})
43
         this.setState({isVisible: true})
43
         break
44
         break
44
       case 'thread_hideApp':
45
       case 'thread_hideApp':
46
+        console.log('%c<Thread> Custom event', 'color: #28a745', type, data)
45
         this.setState({isVisible: false})
47
         this.setState({isVisible: false})
46
         break
48
         break
47
       case 'thread_reloadContent':
49
       case 'thread_reloadContent':
50
+        console.log('%c<Thread> Custom event', 'color: #28a745', type, data)
48
         this.setState(prev => ({content: {...prev.content, ...data}, isVisible: true}))
51
         this.setState(prev => ({content: {...prev.content, ...data}, isVisible: true}))
49
     }
52
     }
50
   }
53
   }
51
 
54
 
52
   componentDidMount () {
55
   componentDidMount () {
53
-    console.log('Thread did Mount')
56
+    console.log('%c<Thread> did Mount', `color: ${this.state.config.hexcolor}`)
54
     this.loadContent()
57
     this.loadContent()
55
   }
58
   }
56
 
59
 
57
   componentDidUpdate (prevProps, prevState) {
60
   componentDidUpdate (prevProps, prevState) {
58
     const { state } = this
61
     const { state } = this
59
 
62
 
60
-    console.log('Thread did Update', prevState, state)
63
+    console.log('%c<Thread> did Mount', `color: ${this.state.config.hexcolor}`, prevState, state)
64
+
61
     if (!prevState.content || !state.content) return
65
     if (!prevState.content || !state.content) return
62
 
66
 
63
     if (prevState.content.content_id !== state.content.content_id) this.loadContent()
67
     if (prevState.content.content_id !== state.content.content_id) this.loadContent()
66
     else if (prevState.timelineWysiwyg && !state.timelineWysiwyg) tinymce.remove('#wysiwygTimelineComment')
70
     else if (prevState.timelineWysiwyg && !state.timelineWysiwyg) tinymce.remove('#wysiwygTimelineComment')
67
   }
71
   }
68
 
72
 
73
+  componentWillUnmount () {
74
+    console.log('%c<Thread> will Unmount', `color: ${this.state.config.hexcolor}`)
75
+    document.removeEventListener('appCustomEvent', this.customEventReducer)
76
+  }
77
+
69
   loadContent = async () => {
78
   loadContent = async () => {
70
     const { loggedUser, content, config } = this.state
79
     const { loggedUser, content, config } = this.state
71
 
80