Explorar o código

simplify render queue

Adam Shaw %!s(int64=7) %!d(string=hai) anos
pai
achega
a38b02cfdc
Modificáronse 3 ficheiros con 26 adicións e 123 borrados
  1. 0 1
      src/Calendar.ts
  2. 9 17
      src/View.ts
  3. 17 105
      src/common/RenderQueue.ts

+ 0 - 1
src/Calendar.ts

@@ -548,7 +548,6 @@ export default class Calendar {
     this.toolbarsManager.proxyCall('deactivateButton', currentView.type)
 
     currentView.removeElement()
-    currentView.unsetDateProfile()
 
     this.view = null
   }

+ 9 - 17
src/View.ts

@@ -98,9 +98,7 @@ export default abstract class View extends InteractiveDateComponent {
 
 
   initRenderQueue() {
-    this.renderQueue = new RenderQueue({
-      event: this.opt('eventRenderWait')
-    })
+    this.renderQueue = new RenderQueue(this.opt('eventRenderWait'))
 
     this.renderQueue.on('start', this.onRenderQueueStart.bind(this))
     this.renderQueue.on('stop', this.onRenderQueueStop.bind(this))
@@ -138,8 +136,8 @@ export default abstract class View extends InteractiveDateComponent {
   }
 
 
-  requestRender(func, namespace, actionType) {
-    this.renderQueue.queue(func, namespace, actionType)
+  requestRender(func) {
+    this.renderQueue.queue(func)
   }
 
 
@@ -245,12 +243,6 @@ export default abstract class View extends InteractiveDateComponent {
   }
 
 
-  unsetDateProfile() {
-    this.unset('dateProfile')
-    this.dateProfile = null
-  }
-
-
   // Date High-level Rendering
   // -----------------------------------------------------------------------------------------------------------------
 
@@ -258,14 +250,14 @@ export default abstract class View extends InteractiveDateComponent {
   requestDateRender() {
     this.requestRender(() => {
       this.executeDateRender()
-    }, 'date', 'init')
+    })
   }
 
 
   requestDateUnrender() {
     this.requestRender(() => {
       this.executeDateUnrender()
-    }, 'date', 'destroy')
+    })
   }
 
 
@@ -343,7 +335,7 @@ export default abstract class View extends InteractiveDateComponent {
       this.whenSizeUpdated(
         this.triggerAfterEventsRendered
       )
-    }, 'event', 'init')
+    })
   }
 
 
@@ -351,7 +343,7 @@ export default abstract class View extends InteractiveDateComponent {
     this.requestRender(() => {
       this.triggerBeforeEventsDestroyed()
       this.unrenderEvents()
-    }, 'event', 'destroy')
+    })
   }
 
 
@@ -362,13 +354,13 @@ export default abstract class View extends InteractiveDateComponent {
   requestBusinessHoursRender() {
     this.requestRender(() => {
       this.renderBusinessHours(this.opt('businessHours'))
-    }, 'businessHours', 'init')
+    })
   }
 
   requestBusinessHoursUnrender() {
     this.requestRender(() => {
       this.unrenderBusinessHours()
-    }, 'businessHours', 'destroy')
+    })
   }
 
 

+ 17 - 105
src/common/RenderQueue.ts

@@ -3,139 +3,51 @@ import TaskQueue from './TaskQueue'
 
 export default class RenderQueue extends TaskQueue {
 
-  waitsByNamespace: any
-  waitNamespace: any
+  waitMs: any
   waitId: any
 
 
-  constructor(waitsByNamespace) {
+  constructor(waitMs) {
     super()
-    this.waitsByNamespace = waitsByNamespace || {}
+    this.waitMs = waitMs
   }
 
 
-  queue(taskFunc, namespace, type) {
-    let task = {
-      func: taskFunc,
-      namespace: namespace,
-      type: type
-    }
-    let waitMs
+  queue(taskFunc) {
 
-    if (namespace) {
-      waitMs = this.waitsByNamespace[namespace]
-    }
+    this.q.push(taskFunc)
 
-    if (this.waitNamespace) {
-      if (namespace === this.waitNamespace && waitMs != null) {
-        this.delayWait(waitMs)
+    if (this.waitMs != null) {
+      if (this.waitId != null) {
+        this.delayWait()
       } else {
-        this.clearWait()
-        this.tryStart()
-      }
-    }
-
-    if (this.compoundTask(task)) { // appended to queue?
-
-      if (!this.waitNamespace && waitMs != null) {
-        this.startWait(namespace, waitMs)
-      } else {
-        this.tryStart()
+        this.startWait()
       }
+    } else {
+      this.tryStart()
     }
   }
 
 
-  startWait(namespace, waitMs) {
-    this.waitNamespace = namespace
-    this.spawnWait(waitMs)
-  }
-
-
-  delayWait(waitMs) {
+  delayWait() {
     clearTimeout(this.waitId)
-    this.spawnWait(waitMs)
+    this.startWait()
   }
 
 
-  spawnWait(waitMs) {
+  startWait() {
     this.waitId = setTimeout(() => {
-      this.waitNamespace = null
+      this.waitId = null
       this.tryStart()
-    }, waitMs)
+    }, this.waitMs)
   }
 
 
   clearWait() {
-    if (this.waitNamespace) {
+    if (this.waitId != null) {
       clearTimeout(this.waitId)
       this.waitId = null
-      this.waitNamespace = null
-    }
-  }
-
-
-  canRunNext() {
-    if (!super.canRunNext()) {
-      return false
-    }
-
-    // waiting for a certain namespace to stop receiving tasks?
-    if (this.waitNamespace) {
-
-      const { q } = this
-
-      // if there was a different namespace task in the meantime,
-      // that forces all previously-waiting tasks to suddenly execute.
-      // TODO: find a way to do this in constant time.
-      for (let i = 0; i < q.length; i++) {
-        if (q[i].namespace !== this.waitNamespace) {
-          return true // allow execution
-        }
-      }
-
-      return false
     }
-
-    return true
-  }
-
-
-  runTask(task) {
-    task.func()
-  }
-
-
-  compoundTask(newTask) {
-    let q = this.q
-    let shouldAppend = true
-    let i
-    let task
-
-    if (newTask.namespace && newTask.type === 'destroy') {
-
-      // remove all init/add/remove ops with same namespace, regardless of order
-      for (i = q.length - 1; i >= 0; i--) {
-        task = q[i]
-
-        switch (task.type) {
-          case 'init':
-            shouldAppend = false
-            // the latest destroy is cancelled out by not doing the init
-            /* falls through */
-          case 'add':
-            /* falls through */
-          case 'remove':
-            q.splice(i, 1) // remove task
-        }
-      }
-    }
-
-    if (shouldAppend) {
-      q.push(newTask)
-    }
-
-    return shouldAppend
   }
 
 }