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,25 +39,29 @@ class Thread extends React.Component {
39 39
   customEventReducer = ({ detail: { type, data } }) => { // action: { type: '', data: {} }
40 40
     switch (type) {
41 41
       case 'thread_showApp':
42
+        console.log('%c<Thread> Custom event', 'color: #28a745', type, data)
42 43
         this.setState({isVisible: true})
43 44
         break
44 45
       case 'thread_hideApp':
46
+        console.log('%c<Thread> Custom event', 'color: #28a745', type, data)
45 47
         this.setState({isVisible: false})
46 48
         break
47 49
       case 'thread_reloadContent':
50
+        console.log('%c<Thread> Custom event', 'color: #28a745', type, data)
48 51
         this.setState(prev => ({content: {...prev.content, ...data}, isVisible: true}))
49 52
     }
50 53
   }
51 54
 
52 55
   componentDidMount () {
53
-    console.log('Thread did Mount')
56
+    console.log('%c<Thread> did Mount', `color: ${this.state.config.hexcolor}`)
54 57
     this.loadContent()
55 58
   }
56 59
 
57 60
   componentDidUpdate (prevProps, prevState) {
58 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 65
     if (!prevState.content || !state.content) return
62 66
 
63 67
     if (prevState.content.content_id !== state.content.content_id) this.loadContent()
@@ -66,6 +70,11 @@ class Thread extends React.Component {
66 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 78
   loadContent = async () => {
70 79
     const { loggedUser, content, config } = this.state
71 80